解密已签名 CMS_ContentInfo* 的内容
Decrypt the content of a signed CMS_ContentInfo*
在使用内存 BIO
时,我在访问签名的 CMS_ContentInfo*
对象中的 EnvelopedData
时遇到问题 BIO
。
使用以下代码,一切正常:
BIO* output = BIO_new_file("/absolute/path/test.txt", "r+");
if (CMS_verify(cms, stack, store, dcont, output, CMS_NOINTERN)) {
BIO_flush(output);
BIO_reset(output);
CMS_ContentInfo* cms2 = SMIME_read_CMS(output, nullptr);
}
cms2 已正确实例化,我能够解密其内容。虽然,我不希望将文件写入磁盘,所以我试图像这样在内存中工作:
BIO* output = BIO_new(BIO_s_mem());
if (CMS_verify(cms, stack, store, dcont, output, CMS_NOINTERN)) {
BIO_flush(output);
BIO_seek(output, 0);
CMS_ContentInfo* cms2 = SMIME_read_CMS(output, nullptr);
}
出于某种原因,SMIME_read_CMS
函数似乎永远无法从 BIO
中读取。谁能帮我解决这个问题?
我找到了我的解决方案。这是我用过的一段代码:
BIO* output = BIO_new(BIO_s_mem());
if (CMS_verify(cms, stack, store, dcont, nullptr, CMS_NOINTERN)) {
CMS_ContentInfo* cms2 = SMIME_read_CMS(dcont, nullptr);
}
显然,它是保存 SignedData
的 dcont BIO
,之后我可以使用 cms2
变量正确解密它。
在使用内存 BIO
时,我在访问签名的 CMS_ContentInfo*
对象中的 EnvelopedData
时遇到问题 BIO
。
使用以下代码,一切正常:
BIO* output = BIO_new_file("/absolute/path/test.txt", "r+");
if (CMS_verify(cms, stack, store, dcont, output, CMS_NOINTERN)) {
BIO_flush(output);
BIO_reset(output);
CMS_ContentInfo* cms2 = SMIME_read_CMS(output, nullptr);
}
cms2 已正确实例化,我能够解密其内容。虽然,我不希望将文件写入磁盘,所以我试图像这样在内存中工作:
BIO* output = BIO_new(BIO_s_mem());
if (CMS_verify(cms, stack, store, dcont, output, CMS_NOINTERN)) {
BIO_flush(output);
BIO_seek(output, 0);
CMS_ContentInfo* cms2 = SMIME_read_CMS(output, nullptr);
}
出于某种原因,SMIME_read_CMS
函数似乎永远无法从 BIO
中读取。谁能帮我解决这个问题?
我找到了我的解决方案。这是我用过的一段代码:
BIO* output = BIO_new(BIO_s_mem());
if (CMS_verify(cms, stack, store, dcont, nullptr, CMS_NOINTERN)) {
CMS_ContentInfo* cms2 = SMIME_read_CMS(dcont, nullptr);
}
显然,它是保存 SignedData
的 dcont BIO
,之后我可以使用 cms2
变量正确解密它。