When I try to decrypt an encrypted S/MIME message using CMS in OpenSSL, the decrypt method returns me 0 which stands for didn't succeed.
OpenSSL.org says..
CMS_decrypt() returns either 1 for success or 0 for failure. The error can be obtained from ERR_get_error(3)
When I run this...
out = BIO_new(BIO_s_mem());
if (!out)
assert(false);
int error = CMS_decrypt(cms, rkey, rcert, out, NULL, 0);
if (!error) {
fprintf(stderr, "Error Decrypting Data\n");
printf("error code: %d\n", ERR_get_error());
ERR_print_errors_fp(stderr);
assert(false);
}
... the error variable is 0 which means an error occurred and the error code from ERR_get_error()
is also 0. Additionally ERR_print_errors_fp()
doesn't print anything which means there was no error.
The output from the aforementioned code:
Error Decrypting Data
error code: 0
Assertion failed: (false)
Does anyone have a suggestion what's going wrong here? Thanks
After many weeks of trying different approaches and frustration I ended up using PKCS#7 decrypt of OpenSSL. Due CMS is basically based on PKCS#7 it works fine with encryption using CMS and decryption using PKCS7.
The method I have used is pkcs7_decrypt()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With