在VB.net中创建和验证PKCS#7签名

时间:2011-01-14 09:44:25

标签: vb.net pkcs#7

我试图弄清楚如何在VB.net中生成和验证PKCS#7签名。这些签名需要存储在他们正在验证的数据的单独文件中(例如test.dat和test.dat.sig)。我找到了在另一个问题中生成签名的代码,但无法弄清楚如何验证它们

Public Sub SignFile(ByVal theFilename As String, ByVal theCertFile As String, ByVal thePassword As String, ByVal theDestination As String)
    Dim aCertificate = New X509Certificates.X509Certificate2(theCertFile, thePassword)
    Dim aByteArray = IO.File.ReadAllBytes(theFilename)
    Dim anOid = New System.Security.Cryptography.Oid("1.2.840.113549.1.7.2")
    Dim aContentInfo = New Pkcs.ContentInfo(anOid, aByteArray)
    Dim aSignedCms = New Pkcs.SignedCms(aContentInfo, True)
    Dim aCmsSigner = New Pkcs.CmsSigner(Pkcs.SubjectIdentifierType.IssuerAndSerialNumber, aCertificate)

    aSignedCms.ComputeSignature(aCmsSigner)
    Dim aSignature = Convert.ToBase64String(aSignedCms.Encode())
    IO.File.WriteAllText(theDestination, aSignature)
End Sub

由于

1 个答案:

答案 0 :(得分:0)

以下内容可能有助于您验证CMS / PKCS#7签名

  

http://www.jensign.com/JavaScience/verify/index.html