When i run the program at the WebApplication.. the error is "An unhandled exception of type 'System.ExecutionEngineException' occurred in mscorlib.dll"
Web service Code:
Dim xmlKeys As String 'A combination of both the public and private keys
Dim xmlPublicKey As String 'The public key only
Dim PlainTextBArray As Byte() 'The plaintext message in a byte array
Dim CypherTextBArray As Byte() 'The cyphertext message in a byte array
<WebMethod()> _
Public Function HelloWorld() As String
'Return "Hello World"
'End Function
Dim rsa As New RSACryptoServiceProvider
xmlPublicKey = rsa.ToXmlString(False)
xmlKeys = rsa.ToXmlString(True)
'get the public key so you can encrypt the message:
rsa.FromXmlString(xmlPublicKey)
'get the message
Dim message As String = "hello String"
If message.Length > 58 Then MsgBox("You must use fewer than 59 characters") : Exit Function
'transform message string into a byte array:
PlainTextBArray = (New UnicodeEncoding).GetBytes(message)
' Encrypt
CypherTextBArray = rsa.Encrypt(PlainTextBArray, False)
'view the cyphertext
Dim Enc As String
For i As Integer = 0 To CypherTextBArray.Length - 1
Enc &= Chr(CypherTextBArray(i))
Next i
Return Enc
Web application Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim test As New localhost.Service1
'TextBox1.Text = test.HelloWorld()
Dim rsa As New RSACryptoServiceProvider
xmlPublicKey = rsa.ToXmlString(False)
xmlKeys = rsa.ToXmlString(True)
'get the keys, thereby creating an RSA object that's identical
'to the one used in the Form_Load event when the keys were first built
rsa.FromXmlString(xmlKeys)
'create a byte array and then put the decrypted plaintext into it
Dim RestoredPlainText As Byte() = rsa.Decrypt(CypherTextBArray, False) << Error Occur at this line..
'Step through the two-byte unicode plaintext, displaying the restored plaintext message
For i As Integer = 0 To (RestoredPlainText.Length - 1) Step 2
TextBox1.Text &= Chr(RestoredPlainText(i))
Next i
End Sub