این هم کد بصورت کامل:


Imports System.Security.Cryptography
Imports System.Text

Public Class EncryptText
'Create a UnicodeEncoder to convert between byte array and string.
Dim ByteConverter As New ASCIIEncoding
'Create a new instance of the RSACryptoServiceProvider class
' and automatically create a new key-pair.
Dim RSAalg As New RSACryptoServiceProvider

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim dataToEncrypt As Byte() = ByteConverter.GetBytes(Me.TextBox1.Text)
Dim encryptedData() As Byte = RSAalg.Encrypt(dataToEncrypt, False)

With Microsoft.Win32.Registry.CurrentUser.OpenSubKey("S ystem", True)
.SetValue("Password", encryptedData, Microsoft.Win32.RegistryValueKind.Binary)
End With
End Sub

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim decryptedData() As Byte
Dim encryptedData() As Byte

With Microsoft.Win32.Registry.CurrentUser.OpenSubKey("S ystem", True)
encryptedData = .GetValue("Password", New Byte() {})
End With
decryptedData = RSAalg.Decrypt(encryptedData, False)
Me.TextBox3.Text = ByteConverter.GetString(decryptedData)
End Sub
End Class