Hi
I am trying to encrypt then decrypt a string using
either RSA_eay_public_decrypt() or
RSA_public_decrypt().
I seem to be able to encrypt the data fine, although I
can't decrypt it, using the corresponding public key
compenent from the RSA structures.
Any feedback would be much appreciated.
Thank
Andy Drake
RSA* rsa=NULL;
RSA *pub_rsa=NULL,*priv_rsa=NULL;
rsa=RSA_generate_key(512, RSA_F4,NULL, NULL);
int len = 0;
unsigned char buf[1024],*p;
p=buf;
//test harness
len=i2d_RSAPublicKey(rsa,&p);
len+=i2d_RSAPrivateKey(rsa,&p);
p=buf;
pub_rsa=d2i_RSAPublicKey(NULL,&p,(long)len);
len-=(p-buf);
priv_rsa=d2i_RSAPrivateKey(NULL,&p,(long)len);
if ((pub_rsa == NULL) || (priv_rsa == NULL))
ERR_print_errors_fp(stderr);
test = new char[512];
buffer = new char[512];
debuffer = new char[512];
strcpy(test, "abcdefgh");
if (rsa)
{
RSA_eay_private_encrypt(8, (unsigned char*) test,
(unsigned char*) buffer, priv_rsa, RSA_PKCS1_PADDING);
//now decrypt it
RSA_eay_public_decrypt(8, (unsigned char*) buffer,
(unsigned char*) debuffer, pub_rsa,
RSA_PKCS1_PADDING);
}
__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]