Hi
I try to use RSA_private_encrypt and OAEP and always get the error at the call
of RSA_private_encrypt :
Error code: 4066076 in .\crypto\rsa\rsa_eay.c line 6029358.
Samplecode:
void SimpleTest()
{
RSA * rsa;
RSA * rsapub;
RSA * rsapri;
unsigned char src[1000] = "1234567";
unsigned char enc[1000] = {0};
unsigned char dec[1000] = {0};
int result;
int pubKeyLen, priKeyLen;
const byte *pubKey;
const byte *priKey;
byte *dummy;
OpenSSL_add_all_algorithms();
if (!(rsa = RSA_generate_key(1024, 0x10001, NULL, NULL)))
return;
pubKeyLen = i2d_RSAPublicKey(rsa, NULL);
pubKey = dummy =(byte *) malloc (pubKeyLen);
i2d_RSAPublicKey(rsa, &dummy);
rsapub = d2i_RSAPublicKey(NULL, &pubKey, pubKeyLen);
priKeyLen = i2d_RSAPrivateKey(rsa, NULL);
priKey = dummy = (byte *) malloc (priKeyLen);
i2d_RSAPrivateKey(rsa, &dummy);
rsapri = d2i_RSAPrivateKey(NULL, &priKey, priKeyLen);
if ((result = RSA_private_encrypt(strlen((char*)src), src, enc, rsapri,
RSA_PKCS1_OAEP_PADDING)) < 0)
{
LogCryptError();
return;
}
if ((result = RSA_public_decrypt(result, enc, dec, rsapub,
RSA_PKCS1_OAEP_PADDING)) < 0)
{
LogCryptError();
return;
}
RSA_free(rsa);
RSA_free(rsapub);
RSA_free(rsapri);
return;
}
Where is my fault? Please help.
Robert