VB.Net Tutorial/Security/RSA — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 12:54, 26 мая 2010
Use RSA to crypt and decrypt
Imports System.Security
Imports System.Security.Cryptography
Imports System.Text
Imports System.IO
Public Class Tester
Public Shared Sub Main
Dim myRSAProvide As New RSACryptoServiceProvider()
Dim strCrypt As String
Dim strResult As String
Dim bteCrypt() As Byte
Dim bteResult() As Byte
Try
strCrypt = "12345678"
bteCrypt = Encoding.ASCII.GetBytes(strCrypt)
bteResult = myRSAProvide.Encrypt(bteCrypt, False)
Console.WriteLine(Encoding.ASCII.GetString(bteResult))
Catch ex As CryptographicException
Console.WriteLine(ex.Message)
End Try
Dim strResault As String
Dim bteDecrypt() As Byte
Try
bteDecrypt = myRSAProvide.Decrypt(bteResult, False)
strResault = Encoding.ASCII.GetString(bteDecrypt)
Console.WriteLine(strResault)
Catch ex As CryptographicException
Console.WriteLine(ex.Message)
End Try
End Sub
End Class