Разные виды шифрования
Код:
'зашифровка/расшифровка любой строчки
Public Const codekey As Byte = 31 'любое число
Function Codec(src As String) As String
Dim i As Long, rez As String
For i = 1 To Len(src)
rez = rez + Chr$(Asc(Mid$(src, i, 1)) Xor codekey)
Next
Codec = rez
End Function
В пространстве имен System.Security.Cryptography реализована масса алгоритмов шифрования/дешифрования данных, такие как DES, RSA, алгоритмы электронно-цифровой подписи DSA, SHA-1, SHA-256, SHA-384, SHA-512, MD5, а также еще много интересного.
Вот рабочий пример:
Код:
Private Sub EncryptData(ByVal inName As String, ByVal outName As String)
'Create the file streams to handle the input and output files.
Dim fin As New FileStream(inName, FileMode.Open, FileAccess.Read)
Dim fout As New FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write)
fout.SetLength(0)
'Create variables to help with read and write.
Dim bin(4096) As Byte 'This is intermediate storage for the encryption.
Dim rdlen As Long = 0 'This is the total number of bytes written.
Dim totlen As Long = fin.Length 'Total length of the input file.
Dim len As Integer 'This is the number of bytes to be written at a time.
Dim des As New DESCryptoServiceProvider
Dim encStream As New CryptoStream(fout, des.CreateEncryptor(), CryptoStreamMode.Write)
Console.WriteLine("Encrypting...")
'Read from the input file, then encrypt and write to the output file.
While rdlen < totlen
len = fin.Read(bin, 0, 4096)
encStream.Write(bin, 0, len)
rdlen = Convert.ToInt32(rdlen + len / des.BlockSize * des.BlockSize)
Console.WriteLine("Processed {0} bytes, {1} bytes total", len, rdlen)
End While
encStream.Close()
End Sub