1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
| Module Module1
Public Key As Byte() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} 'Ключ
Public IV As Byte() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} 'Вектор инициализации
Public Sub Encrypt(ByVal fName As String, ByVal txtEncrypt As String)
Dim RMCrypto As New Security.Cryptography.RijndaelManaged
Dim fs As New IO.FileStream(fName, IO.FileMode.Create)
Dim CryptStream As New Security.Cryptography.CryptoStream(fs, RMCrypto.CreateEncryptor(Key, IV), Security.Cryptography.CryptoStreamMode.Write)
Dim SWriter As New IO.StreamWriter(CryptStream)
SWriter.Write(txtEncrypt)
SWriter.Close()
fs.Close()
CryptStream.Close()
End Sub
Public Function Decrypt(ByVal fName As String) As String
Dim RMCrypto As New Security.Cryptography.RijndaelManaged
Dim fs As New IO.FileStream(fName, IO.FileMode.Open)
Dim CryptStream As New Security.Cryptography.CryptoStream(fs, RMCrypto.CreateDecryptor(Key, IV), Security.Cryptography.CryptoStreamMode.Read)
Dim SReader As New IO.StreamReader(CryptStream)
Decrypt = SReader.ReadToEnd()
SReader.Close()
fs.Close()
CryptStream.Close()
End Function
End ModuleModule Module1
Public Key As Byte() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} 'Ключ
Public IV As Byte() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} 'Вектор инициализации
Public Sub Encrypt(ByVal fName As String, ByVal txtEncrypt As String)
Dim RMCrypto As New Security.Cryptography.RijndaelManaged
Dim fs As New IO.FileStream(fName, IO.FileMode.Create)
Dim CryptStream As New Security.Cryptography.CryptoStream(fs, RMCrypto.CreateEncryptor(Key, IV), Security.Cryptography.CryptoStreamMode.Write)
Dim SWriter As New IO.StreamWriter(CryptStream)
SWriter.Write(txtEncrypt)
SWriter.Close()
fs.Close()
CryptStream.Close()
End Sub
Public Function Decrypt(ByVal fName As String) As String
Dim RMCrypto As New Security.Cryptography.RijndaelManaged
Dim fs As New IO.FileStream(fName, IO.FileMode.Open)
Dim CryptStream As New Security.Cryptography.CryptoStream(fs, RMCrypto.CreateDecryptor(Key, IV), Security.Cryptography.CryptoStreamMode.Read)
Dim SReader As New IO.StreamReader(CryptStream)
Decrypt = SReader.ReadToEnd()
SReader.Close()
fs.Close()
CryptStream.Close()
End Function
End Module |