OpenSSL签名和CAPI验证

时间:2015-05-29 02:43:11

标签: c++ com openssl mscapi

我正在使用CAPICOM libary,但它在Android和iOS上不可用。据我所知,CAPICOM签名消息是PKCS#7格式,然后我想用OpenSSL创建像CAPICOM那样的签名消息。

我使用的OpenSSL命令:

iconv -f utf-8 -t utf-16le data.bin > data-utf16le.bin

openssl smime -sign -binary -noattr -in data-utf16le.bin -signer demo.pem -inkey demo.key -out sign.txt -outform PEM

然后我用CAPICOM验证了这个样本:http://www.codeproject.com/Articles/9691/Using-CAPICOM-in-NET-for-Digital-Signatures-with-A

验证方法是:

public bool VerifyDetachedSignature(string plaintextMessage, string signedContent, Encoding encodingType) 
{
    try
    {
        this._clearText = plaintextMessage;
        this._signedContent = signedContent;
        CAPICOM.SignedData signedData = new CAPICOM.SignedDataClass();
        CAPICOM.Utilities u = new CAPICOM.UtilitiesClass();
        IntPtr _content = u.ByteArrayToBinaryString(encodingType.GetBytes(plaintextMessage));
                signedData.set_Content(_content);
        int len = _signedContent.Length;
        signedData.Verify(_signedContent,true, CAPICOM.CAPICOM_SIGNED_DATA_VERIFY_FLAG.CAPICOM_VERIFY_SIGNATURE_ONLY);
        SignerCert=null;
        CAPICOM.Signer s = (CAPICOM.Signer) signedData.Signers[1];
        SignerCert = (CAPICOM.Certificate)s.Certificate;                
        return true;                    
    }
    catch(COMException e)
    {
        return false;
    }
}

encodingTypeSystem.Text.Encoding.UTF8

结果无效。

我再次使用CAPICOM签名,我发现在这种情况下签名邮件的长度比OpenSSL创建的签名邮件的长度长。

请帮助我理解!

0 个答案:

没有答案