gpt4 book ai didi

c - 解密已签名 CMS_ContentInfo* 的内容

转载 作者:太空宇宙 更新时间:2023-11-03 23:47:42 26 4
gpt4 key购买 nike

在使用内存 BIO 时,我在访问签名的 CMS_ContentInfo* 对象中的 EnvelopedData 时遇到问题。

使用下面的代码,一切正常:

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 变量正确解密它。

关于c - 解密已签名 CMS_ContentInfo* 的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28967560/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com