【问题标题】:print digital signature infos打印数字签名信息
【发布时间】:2023-03-18 14:47:01
【问题描述】:

如标题所示,我想将数字签名信息打印到控制台。这是我写的代码:

bool CheckDigSig(const std::wstring& filepath)
{
    bool rval = false;

    DWORD dwEncoding = 0;
    DWORD dwContentType = 0;
    DWORD dwFormatType = 0;
    HCERTSTORE hStore = NULL;
    HCRYPTMSG hMsg = NULL;

    // Get message handle and store handle from the signed file.
    BOOL fResult = CryptQueryObject(CERT_QUERY_OBJECT_FILE,
        filepath.c_str(),
        CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED,
        CERT_QUERY_FORMAT_FLAG_BINARY,
        0,
        &dwEncoding,
        &dwContentType,
        &dwFormatType,
        &hStore,
        &hMsg,
        NULL);
    if (!fResult)
        return false;

    DWORD singer_info_size = 0;
    // Get signer information size.
    fResult = CryptMsgGetParam(hMsg, CMSG_SIGNER_INFO_PARAM, 0, NULL, &singer_info_size);
    if (!fResult)
    {
        CryptMsgClose(hMsg);
        CertCloseStore(hStore, 0);
        return false;
    }

    // Allocate memory for signer information.
    std::vector<byte> signer_info_data(singer_info_size);
    PCMSG_SIGNER_INFO pSignerInfo = reinterpret_cast<PCMSG_SIGNER_INFO>(signer_info_data.data());

    // Get Signer Information.
    fResult = CryptMsgGetParam(hMsg, CMSG_SIGNER_INFO_PARAM, 0, (PVOID)pSignerInfo, &singer_info_size);
    if (fResult)
    {
        //pSignerInfo->Issuer;
        //pSignerInfo->SerialNumber;
    }

    CryptMsgClose(hMsg);
    CertCloseStore(hStore, 0);
    return rval;
}

我想在最后打印这两个变量(现在推荐): pSignerInfo->发行者; pSignerInfo->序列号;

我不知道如何使它成为可读格式,如字符串、字节或字符数组。你能帮我解决一下吗?

【问题讨论】:

    标签: c++ visual-c++ digital-signature digital-certificate


    【解决方案1】:

    这篇文章http://support.microsoft.com/kb/323809有你需要的代码。这是它的一个简短的sn-p:

        // Get Issuer name.
        if (!(CertGetNameString(pCertContext, 
                                CERT_NAME_SIMPLE_DISPLAY_TYPE,
                                CERT_NAME_ISSUER_FLAG,
                                NULL,
                                szName,
                                dwData)))
        // ...
    

    显然,其中包含更多代码,涵盖了此任务的各个方面。包括打印SerialNumber 以及

    【讨论】:

      猜你喜欢
      • 2010-10-19
      • 2014-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多