我想解密并验证已签名和加密的文件。
代码如下所示(签名并加密文件):
//open file
bio_file_in = BIO_new_file("fileA", "rb");
//signe file to mem
cms = CMS_sign(scert, skey, NULL, bio_file_in, CMS_NOSMIMECAP|CMS_BINARY);
BIO *mem = BIO_new(BIO_s_mem());
SMIME_write_CMS(mem, cms, bio_file_in, CMS_NOSMIMECAP|CMS_BINARY)
//encrypted
en_cms = CMS_encrypt(recips, mem, EVP_aes_128_cbc(), CMS_BINARY);
en_out_bio = BIO_new_file("fileA.cms.en", "wb");
//save file
SMIME_write_CMS(en_out_bio, en_cms, mem, CMS_BINARY)
解密和验证码如下所示:
bio_file_in = BIO_new_file("fileA.cms.en", "rb");
cms_enc = SMIME_read_CMS(bio_file_in, NULL);
BIO *mem = BIO_new(BIO_s_mem());
CMS_decrypt(cms_enc, dec_key, dec_cert, NULL, mem, CMS_BINARY)
cms_ver = SMIME_read_CMS(mem, NULL);
CMS_verify(cms_ver, NULL, ver_st, NULL, out_file_bio, CMS_NOSMIMECAP|CMS_BINARY)
执行以下行时发生错误
cms_ver = SMIME_read_CMS(dec_bio, NULL);
错误:0D0D40D1:asn1编码例程:SMIME_read_ASN1:无内容类型
我不知道问题出在哪里以及如何解决问题?