Hello,
I want to encrypt a small data using recipient public key and decrypt it on
the receiver side using recipient private key. I chose "PKCS7_encrypt" and
"PKCS7_decrypt" api to do so. Are they the correct functions? Is there any
other alternative?
Now my problem is that I want to convert the encrypted output of
"PKCS7_encrypt" to char* to send it over TCP. I used
"i2d_PKCS7_fp", "d2i_PKCS7_bio" and "d2i_PKCS7_fp" to first write them in
the file and later on read them and send them. Here is the procedure to
encrypt:
* p7 = PKCS7_encrypt(recips, in, EVP_des_ede3_cbc(), flags);*
* if (!p7)*
* goto err;*
*
*
* FILE *fp = NULL;*
* char *file = "Hello";*
* size_t len = 0;*
* fp = fopen(file, "w");*
* if (fp == NULL) {*
* printf("Error in opening a file..", file);*
* }*
* i2d_PKCS7_fp(fp, p7);*
*
*
* fclose(fp);*
And here is the code to decrypt? Is the procedure to convert is correct?
* FILE *p = NULL;*
* char *file = "Hello";*
* p = fopen(file, "r");*
* if (p == NULL) {*
* printf("Error in opening a file..", file);*
* }*
* d2i_PKCS7_fp(p, &p7);*
* fclose(p);*
*
*
* if (!p7)*
* goto err;*
*
*
* BIO* out;*
* d2i_PKCS7_bio(out, &p7);*
* *
* if (!(&out2))*
* goto err;*
*
*
* /* Decrypt S/MIME message */*
* if (!PKCS7_decrypt(p7, rkey, rcert, &out, 0))*
* goto err;*
It does not work and even the "out" is not initialized. Any suggestion?
Thanks a lot