P
Peter
I wrote this rsa proceedure that works great:
Dim xmlPublicKey As String =
"<RSAKeyValue><Modulus>qZphGJhaxkcSkQiKbzbp4PqWgC0VsFthijbZ1tioCCayBH+7QUwiOzzC9AAu/cTyemxf2YYXA9ozbafsPjvV2T7dOEVVs3bRooKbSPTwxQWwny5pgexOPABBf7vGmtq9r2/mMWnCGMXRGscW2UtV/FFfb1ga6yC9ovGEUM8kpvU=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>"
Dim rsa As New RSACryptoServiceProvider
rsa.FromXmlString(xmlPublicKey)
Dim message As String = "Entcrypt this data"
Dim plainTextinBytes As Byte()
plainTextinBytes = (New UnicodeEncoding).GetBytes(message)
Try
plainTextinBytes = rsa.Encrypt(plainTextinBytes, False)
Catch ex As CryptographicException
MsgBox(ex.ToString)
End Try
For i As Integer = 0 To plainTextinBytes.Length - 1
txtReg.Text += (Chr(plainTextinBytes(i)))
Me.Refresh()
Next
And I can decrypt this message from within the same proceedure with no
issues:
rsa.FromXmlString("<RSAKeyValue><Modulus>qZphGJhaxkcSkQiKbzbp4PqWgC0VsFthijbZ1tioCCayBH+7QUwiOzzC9AAu/cTyemxf2YYXA9ozbafsPjvV2T7dOEVVs3bRooKbSPTwxQWwny5pgexOPABBf7vGmtq9r2/mMWnCGMXRGscW2UtV/FFfb1ga6yC9ovGEUM8kpvU=</Modulus><Exponent>AQAB</Exponent><P>2LLhPL5KkAVVkJpk9Z2aXiuaRkftfdWpKzwPoJ1XywWvQagZj63scCUlxV/DDU6alG7GEduMK6XFqPJWwDhNCw==</P><Q>yFzj0cjy71Cv+Knpq09jmw7m4yLu6TdbmYxyqce10Jg3Kyff7E8iE
KqDANvhUE2rLKMpIla5f2ZP0G3JSdb/w==</Q><DP>y+BIT1kNV8DdBuZr1DYKVU0aocLsazaJKbchUNCYF9fqUpBwNCDDUaNxjOgS4EMy5jHuQkDX+PzHIbOW8NRHjw==</DP><DQ>vOnYZBRz+fC5+ls6Vquj3q9OQxrM6Feppj0mX65NX0AlxCr0lnqGRFK0wl7650l1o581vG1Fp1RVCa+MXxudQQ==</DQ><InverseQ>aRzkx6cn4aGwHQ1l5qadZFgrCJr43dzEAGZm7Uo+8+cb8uN12RxoPWsk0pmwaprZhIapAo/tqWtJ1SnyN7iJ2Q==</InverseQ><D>Q43yTtGglomIo6w7N8EvtyUY/UT39p7vYxYl/qWdiGGhVplqBMBGgkHZ
UbtcLcZvhmctA/s6uPmyC6ysrcyngeE5fdWlTZWTlgihOMh/g7AnYRvyY4iQ9W0g3691HzoNDC+kNhsO4LHbEwhmq7OgCigFNd0oHlDhQYQqhZjGKE=</D></RSAKeyValue>")
'plainTextinBytes = (New
UnicodeEncoding).GetBytes(txtReg.Text)
Dim decrytion As Byte() = rsa.Decrypt(plainTextinBytes, False)
For i As Integer = 0 To (decrytion.Length - 1) Step 2
Console.Write(Chr(decrytion(i)))
Next
But I can not get this message to decrypt in another program. If all
I have is the private key and the encrypted message how should my
decrypt proceedure look?
-Peter
Dim xmlPublicKey As String =
"<RSAKeyValue><Modulus>qZphGJhaxkcSkQiKbzbp4PqWgC0VsFthijbZ1tioCCayBH+7QUwiOzzC9AAu/cTyemxf2YYXA9ozbafsPjvV2T7dOEVVs3bRooKbSPTwxQWwny5pgexOPABBf7vGmtq9r2/mMWnCGMXRGscW2UtV/FFfb1ga6yC9ovGEUM8kpvU=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>"
Dim rsa As New RSACryptoServiceProvider
rsa.FromXmlString(xmlPublicKey)
Dim message As String = "Entcrypt this data"
Dim plainTextinBytes As Byte()
plainTextinBytes = (New UnicodeEncoding).GetBytes(message)
Try
plainTextinBytes = rsa.Encrypt(plainTextinBytes, False)
Catch ex As CryptographicException
MsgBox(ex.ToString)
End Try
For i As Integer = 0 To plainTextinBytes.Length - 1
txtReg.Text += (Chr(plainTextinBytes(i)))
Me.Refresh()
Next
And I can decrypt this message from within the same proceedure with no
issues:
rsa.FromXmlString("<RSAKeyValue><Modulus>qZphGJhaxkcSkQiKbzbp4PqWgC0VsFthijbZ1tioCCayBH+7QUwiOzzC9AAu/cTyemxf2YYXA9ozbafsPjvV2T7dOEVVs3bRooKbSPTwxQWwny5pgexOPABBf7vGmtq9r2/mMWnCGMXRGscW2UtV/FFfb1ga6yC9ovGEUM8kpvU=</Modulus><Exponent>AQAB</Exponent><P>2LLhPL5KkAVVkJpk9Z2aXiuaRkftfdWpKzwPoJ1XywWvQagZj63scCUlxV/DDU6alG7GEduMK6XFqPJWwDhNCw==</P><Q>yFzj0cjy71Cv+Knpq09jmw7m4yLu6TdbmYxyqce10Jg3Kyff7E8iE
KqDANvhUE2rLKMpIla5f2ZP0G3JSdb/w==</Q><DP>y+BIT1kNV8DdBuZr1DYKVU0aocLsazaJKbchUNCYF9fqUpBwNCDDUaNxjOgS4EMy5jHuQkDX+PzHIbOW8NRHjw==</DP><DQ>vOnYZBRz+fC5+ls6Vquj3q9OQxrM6Feppj0mX65NX0AlxCr0lnqGRFK0wl7650l1o581vG1Fp1RVCa+MXxudQQ==</DQ><InverseQ>aRzkx6cn4aGwHQ1l5qadZFgrCJr43dzEAGZm7Uo+8+cb8uN12RxoPWsk0pmwaprZhIapAo/tqWtJ1SnyN7iJ2Q==</InverseQ><D>Q43yTtGglomIo6w7N8EvtyUY/UT39p7vYxYl/qWdiGGhVplqBMBGgkHZ
UbtcLcZvhmctA/s6uPmyC6ysrcyngeE5fdWlTZWTlgihOMh/g7AnYRvyY4iQ9W0g3691HzoNDC+kNhsO4LHbEwhmq7OgCigFNd0oHlDhQYQqhZjGKE=</D></RSAKeyValue>")
'plainTextinBytes = (New
UnicodeEncoding).GetBytes(txtReg.Text)
Dim decrytion As Byte() = rsa.Decrypt(plainTextinBytes, False)
For i As Integer = 0 To (decrytion.Length - 1) Step 2
Console.Write(Chr(decrytion(i)))
Next
But I can not get this message to decrypt in another program. If all
I have is the private key and the encrypted message how should my
decrypt proceedure look?
-Peter