我对 x509certificates 类有一些问题。
这些代码适用于 USB 记忆棒。但不能工作“.cer”文件。
公共函数 signString(ByVal msg As String, ByVal imzasahibi As String) As String
Dim unicode As Encoding = Encoding.UTF8
Dim msgBytes As Byte() = unicode.GetBytes(msg)
Dim signerCert As X509Certificate2 = GetSignerCert(imzasahibi)
Dim encodedSignedCms As Byte() = SignMsg(msgBytes, signerCert)
Dim result As String = Convert.ToBase64String(encodedSignedCms)
If Not VerifyMsg(msgBytes, encodedSignedCms) Then
Throw New Exception("Any problems")
End If
Return result
End Function
公共函数 MesajImzala(ByVal msg As String, ByVal imzasahibi As String) As String
Dim sertifikamiz As String = HttpContext.Current.Server.MapPath("certificateFiles/testFile.cer")
Dim signerCert As X509Certificate2 = X509Certificate2.CreateFromCertFile(sertifikamiz)
Dim unicode As Encoding = Encoding.UTF8
Dim msgBytes As Byte() = unicode.GetBytes(msg)
Dim encodedSignedCms As Byte() = SignMsg(msgBytes, signerCert)
Dim result As String = Convert.ToBase64String(encodedSignedCms)
If Not VerifyMsg(msgBytes, encodedSignedCms) Then
Throw New Exception("Any problems")
End If
Return result
End Function
如果你想我发送文件。谢谢你们...
说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.InvalidCastException: 'System.Security.Cryptography.X509Certificates.X509Certificate' türündeki nesne 'System.Security.Cryptography.X509Certificates.X509Certificate2' türüne atılamadı。