【问题标题】:Decrypt the content of a signed CMS_ContentInfo*解密已签名的 CMS_ContentInfo* 的内容
【发布时间】:2015-03-10 15:22:07
【问题描述】:

在使用内存 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 中读取。谁能帮我解决这个问题?

【问题讨论】:

    标签: c openssl libcrypto


    【解决方案1】:

    我找到了我的解决方案。这是我使用的一段代码:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-21
      • 1970-01-01
      • 2013-08-29
      • 2016-03-27
      • 2012-06-19
      • 1970-01-01
      相关资源
      最近更新 更多