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
感謝