Sorry.... I don't have time to do a wiki page.
Jeff
jeffrey@studio:~$ cat cryptopp-test.cpp
// g++ -g3 -ggdb -O0 -DDEBUG -I/usr/include/cryptopp cryptopp-test.cpp
-o cryptopp-test.exe -lcryptopp -lpthread
// g++ -g -O2 -DNDEBUG -I/usr/include/cryptopp cryptopp-test.cpp -o
cryptopp-test.exe -lcryptopp -lpthread
#include <iostream>
using std::cout;
using std::endl;
#include <iomanip>
using std::hex;
#include <string>
using std::string;
#include "filters.h"
using CryptoPP::Redirector;
using CryptoPP::StringSource;
using CryptoPP::StringSink;
using CryptoPP::ArraySink;
#include "osrng.h"
using CryptoPP::AutoSeededRandomPool;
#include "rsa.h"
using CryptoPP::RSA;
#include "integer.h"
using CryptoPP::Integer;
int main(int argc, char** argv)
{
AutoSeededRandomPool prng;
RSA::PrivateKey privKey;
privKey.GenerateRandomWithKeySize(prng, 256);
RSA::PublicKey pubKey(privKey);
string message, recovered;
Integer m, c, r;
message = "secret";
cout << "message: " << message << endl;
// Treat the message as a big endian array
m = Integer((const byte *)message.data(), message.size());
cout << "m: " << hex << m << endl;
c = pubKey.ApplyFunction(m);
cout << "c: " << hex << c << endl;
r = privKey.CalculateInverse(prng, c);
cout << "r: " << hex << r << endl;
// Round trip it
size_t req = r.MinEncodedSize();
recovered.resize(req);
r.Encode((byte *)recovered.data(), recovered.size());
cout << "recovered: " << recovered << endl;
return 0;
}
jeffrey@studio:~$ ./cryptopp-test.exe
message: secret
m: 736563726574h
c: 7cad7eb273c4f563948f0e09e038724f6455f683214661321968eb595a8f7a1fh
r: 736563726574h
recovered: secret
jeffrey@studio:~$
On Feb 12, 4:55 am, Jeffrey Walton <[email protected]> wrote:
> On Feb 9, 10:20 pm, Leonardo Carreira <[email protected]> wrote:> Hi Jeff,
>
> > I'm still struggling to solve this.
> > How to specify No Padding usage using Cryptopp?
> > Because i want to encrypt the data with length is the same with
> > modulus length.
> > As far as i know, in Cryptopp there're only 2 typedef option which can
> > be used, but all of these classes uses Padding..
>
> > typedef RSAES<PKCS1v15>::Decryptor RSAES_PKCS1v15_Decryptor;
> > typedef RSAES<PKCS1v15>::Encryptor RSAES_PKCS1v15_Encryptor;
>
> > typedef RSAES<OAEP<SHA> >::Decryptor RSAES_OAEP_SHA_Decryptor;
> > typedef RSAES<OAEP<SHA> >::Encryptor RSAES_OAEP_SHA_Encryptor;
>
> I think the long way (but probably the correct way) is to derive a
> class from PK_EncryptionMessageEncodingMethod (http://www.cryptopp.com/
> docs/ref/class_p_k___encryption_message_encoding_method.html).
>
> I think the shortest path would probably call ApplyFunction on
> InvertibleRSAFunction (InvertibleRSAFunction is a typedef for
> RSA::PrivateKey -
> seehttp://www.cryptopp.com/docs/ref/class_invertible_r_s_a_function.html
> andhttp://www.cryptopp.com/docs/ref/struct_r_s_a.html). So you are
> basically calling Encrypt with the private key.
> RSAFunction::ApplyFunction should perform the decrypt. I've never
> tried to write or run the code, though.
>
> Jeff
>
> [SNIP]
--
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at
http://www.cryptopp.com.