I send a string of the client's public key from a pem file and want to use this string to do decryption on server without writing the string into another pem file. How can I do it?
read key code:
if ( (my_public_key = PEM_read_RSA_PUBKEY(fp, NULL, My_PWD, NULL)) == NULL) {
ERR_print_errors_fp(stdout);
fclose(fp);
return;
}
do decrypt code:
rsa_len = RSA_size(target_public_key);
p_de = (unsigned char*)malloc(rsa_len+1);
memset(p_de, 0, rsa_len+1);
if (RSA_public_decrypt(rsa_len, (unsigned char*)from_hex,p_de , target_public_key, RSA_NO_PADDING) <0) {
perror("can't decrypt data!");
return;
}