رمزگذاری متن و ذخیره سازی بصورت Binary در رجیستری
سلام
این دومین دستور رمزگذاری متن هست که من به اشتراک می گذارم (اولیش این بوده: آموزش: تبدیل پسور کاربر به متن امن برای ذخیره در دیتابیس) و کد ساده ای داره و همچنین شاید امنیت بالایی نداشته باشه برای متن هایی که خیلی مهم نیستند (یعنی کمی مهم) می شه استفاده کرد.
مراجع مورد نیاز:
Imports System.Security.Cryptography
Imports System.Text
متغیرهای با سطح دسترسی در ماجول کد:
'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
رمز گذاری متن TextBox1 و ذخیره سازی در رجیستری بصورت Binary:
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
فراخوانی مقدار ذخیره سازی شده از رجیستری و رمزگشایی مقدار و نمایش متن رمزگشایی دشه در TextBox2:
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)
کد کامل در پست بعدی....
نقل قول: رمزگذاری متن و ذخیره سازی بصورت Binary در رجیستری
این هم کد بصورت کامل:
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