Hi all,
i'd like some advice on a problem i'm getting on a very simple piece of code, i'm just trying to encrypt a string using rsa and then decrypt it, nothing complicated really. Encryption seems to works fine but when i try to decrypt, i'm only getting 4 characters whatever the size of the string. Those 4 characters are good but i'd like to have the rest of the string !! could someone help me ?
code follows :
#include <openssl/rsa.h>
#define MYPADDING RSA_PKCS1_PADDING
char *mystring = "hello openssl";
try 'char mystring[] = "hello openssl";' (or use 'strlen(mystring) + 1' instead of the sizeof operator)
char *mystring_encrypted = 0; char *mystring2 = 0; int ret1, ret2;
int main(void) {
RAND_load_file("/dev/urandom", 16384);
RSA *rsa = RSA_generate_key(2048, 65537, NULL, NULL);
printf("RSA_size : %d\n", RSA_size(rsa));
mystring_encrypted = malloc(RSA_size(rsa));
bzero(mystring_encrypted, RSA_size(rsa));
ret1=RSA_public_encrypt(sizeof(mystring),mystring,mystring_encrypted,rsa,MYPADDING);
hmm, sizeof(mystring) == sizeof(char *) == 4
printf("ret1 : %d\n", ret1);
mystring2 = malloc(ret1);
bzero(mystring2, ret1);
ret2=RSA_private_decrypt(ret1,mystring_encrypted,mystring2,rsa,MYPADDING);
printf("ret2 : %d [%s]\n", ret2, mystring2);
}
Regards, Nils
Btw: [EMAIL PROTECTED] would be more appropriate for this kind
of questions.______________________________________________________________________ OpenSSL Project http://www.openssl.org Development Mailing List [EMAIL PROTECTED] Automated List Manager [EMAIL PROTECTED]
