05-09-15, 01:02 PM
سلام
هذا الرابط فيه التشفير وفك التشفير
https://msdn.microsoft.com/en-us/library/ms172831.aspx
موفقين
هذا الرابط فيه التشفير وفك التشفير
https://msdn.microsoft.com/en-us/library/ms172831.aspx
كود :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String = "الطالب"
Dim es As String = EncryptData(s)
MsgBox(es)
Dim ds As String = DecryptData(es)
MsgBox(ds)
End Sub
#Region " Encrypting and Decrypting "
'https://msdn.microsoft.com/en-us/library/ms172831(v=vs.100).aspx
Private TripleDes As New Security.Cryptography.TripleDESCryptoServiceProvider
Public Function EncryptData(ByVal plaintext As String) As String
' Convert the plaintext string to a byte array.
Dim plaintextBytes() As Byte = System.Text.Encoding.Unicode.GetBytes(plaintext)
' Create the stream.
Dim ms As New System.IO.MemoryStream
' Create the encoder to write to the stream.
Dim encStream As New Security.Cryptography.CryptoStream(ms, TripleDes.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write)
' Use the crypto stream to write the byte array to the stream.
encStream.Write(plaintextBytes, 0, plaintextBytes.Length)
encStream.FlushFinalBlock()
' Convert the encrypted stream to a printable string.
Return Convert.ToBase64String(ms.ToArray)
End Function
Public Function DecryptData(ByVal encryptedtext As String) As String
' Convert the encrypted text string to a byte array.
Dim encryptedBytes() As Byte = Convert.FromBase64String(encryptedtext)
' Create the stream.
Dim ms As New System.IO.MemoryStream
' Create the decoder to write to the stream.
Dim decStream As New Security.Cryptography.CryptoStream(ms, TripleDes.CreateDecryptor, System.Security.Cryptography.CryptoStreamMode.Write)
' Use the crypto stream to write the byte array to the stream.
decStream.Write(encryptedBytes, 0, encryptedBytes.Length)
decStream.FlushFinalBlock()
' Convert the plaintext stream to a string.
Return System.Text.Encoding.Unicode.GetString(ms.ToArray)
End Function
#End Regionموفقين
متغيب
