I tried to use
p7=d2i_PKCS7_bio(in,NULL);
instead of
p7 = SMIME_read_PKCS7(in, NULL);
and it works great.
I hope it will help someone.
Pergunta
I'm trying to decrypt p7m with OpenSSL but I cannot go through the error in the following part of the code:
PKCS7 *p7 = NULL;
in = BIO_new_file(convertedResourcePath, "r");
if (in) {
NSLog(@"opening p7m file");
}
else
NSLog(@"cannot found p7m file");
out = BIO_new_file(convertedDecrFilePath, "w");
if (out) {
NSLog(@"file for decription has been created");
}
else
NSLog(@"failed to create decription file");
p7 = SMIME_read_PKCS7(in, NULL);
if (p7) {
NSLog(@"start reading p7m file");
}
else {
NSLog(@"cannot read p7m file");
ERR_print_errors_fp(stderr);
}
if (PKCS7_decrypt(p7, pkey, cert, out, 0)) {
NSLog(@"file decrypted sucessfully!");
}
else
NSLog(@"cannot decrypt file");
I got the following in output:
opening p7m file 2013-07-22 12:45:22.951 smimePrototype[10827:c07] file for decription has been created 2013-07-22 12:45:22.952 smimePrototype[10827:c07] cannot read p7m file 2900150892:error:0D0D40D1:asn1 encoding routines:SMIME_read_ASN1:no content type:asn_mime.c:451: 2013-07-22 12:45:22.953 smimePrototype[10827:c07] cannot decrypt file
Looking for your help, maybe p7 variable can be initialized in other way?
Solução
I tried to use
p7=d2i_PKCS7_bio(in,NULL);
instead of
p7 = SMIME_read_PKCS7(in, NULL);
and it works great.
I hope it will help someone.