2011-01-14 69 views
0

我试图弄清楚如何在VB.net中生成和验证PKCS#7签名。这些签名需要存储在他们正在验证的数据的单独文件中(例如test.dat和test.dat.sig)。香港专业教育学院发现代码生成另一个问题签名,但无法弄清楚如何验证他们在VB.net中创建并验证PKCS#7签名

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 

感谢

回答