I've been stumped by this one for a while now and can't seem to find
the problem. I've simplified my code to the code below. Randomly,
the binary data will not decrypt back to normal. I'm not sure if this
is the correct way to decrypt binary data because there is a string
conversion. Here is what I have. If I run it 50 times it will not
decrypt correctly about 4 times. What could the problem be? Thanks.
#include <crypto++/dll.h>
#include <crypto++/aes.h>
#include <crypto++/modes.h>
#include <crypto++/filters.h>
#include <cstring>
using namespace CryptoPP;
using namespace std;
#define SIZE 16
int main(void)
{
AutoSeededRandomPool rng;
InvertibleRSAFunction params;
params.GenerateRandomWithKeySize(rng, 1536);
RSA::PrivateKey id3sk(params);
RSA::PublicKey id3pk(params);
RSAES_OAEP_SHA_Decryptor d(id3sk);
RSAES_OAEP_SHA_Encryptor e(id3pk);
string encrypted_data;
byte data[SIZE];
byte decrypted_data[SIZE];
rng.GenerateBlock(data, SIZE);
for(int x = 0; x < SIZE; x++) {
printf("%X%X", (data[x] & 240) >> 4, (data[x] & 15));
}
cout << endl;
ArraySource((char *)data, true, new PK_EncryptorFilter(rng, e,
new StringSink(encrypted_data)));
StringSource(encrypted_data, true, new PK_DecryptorFilter(rng,
d, new ArraySink(decrypted_data, SIZE)));
for(int x = 0; x < SIZE; x++) {
printf("%X%X", (decrypted_data[x] & 240) >> 4,
(decrypted_data[x] & 15));
}
cout << endl;
return 0;
}
--
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.