x509certificates クラスに問題があります。
これらのコードは USB スティックで動作します。しかし、「.cer」ファイルは機能しません。
Public Function 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
Public 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ı.