Imports System.Security.Cryptography
dim plainText = "This is some test text"
Console.WriteLine("Plain Text: " & plainText)
Console.WriteLine(plainText)
dim byteArray() = Encoding.ASCII.GetBytes( plainText )
dim stream = new MemoryStream( byteArray )
dim cipherBytes = encrypt(stream)
Console.WriteLine("Cipher Bytes: ")
for each b in cipherBytes
Console.Write(b.ToString() + " ")
Public Function Encrypt(InputStream As Stream) As Byte()
Dim outputStream = New MemoryStream()
Dim EncryptionKey As String = "MAKV2SPBNI99212"
Using encryptor As Aes = Aes.Create()
Dim pdb As New Rfc2898DeriveBytes(EncryptionKey, New Byte() {&H49, &H76, &H61, &H6E, &H20, &H4D, &H65, &H64, &H76, &H65, &H64, &H65, &H76})
encryptor.Key = pdb.GetBytes(32)
encryptor.IV = pdb.GetBytes(16)
Using cs As New CryptoStream(outputStream, encryptor.CreateEncryptor(), CryptoStreamMode.Write)
While (Assign(data, InputStream.ReadByte())) <> -1
cs.WriteByte(CByte(data))
Return outputStream.GetBuffer()
Public Function Decrypt(InputStream As Stream) As Byte()
Dim outputStream = New MemoryStream()
Dim EncryptionKey As String = "MAKV2SPBNI99212"
Using encryptor As Aes = Aes.Create()
Dim pdb As New Rfc2898DeriveBytes(EncryptionKey, New Byte() {&H49, &H76, &H61, &H6E, &H20, &H4D, &H65, &H64, &H76, &H65, &H64, &H65, &H76})
encryptor.Key = pdb.GetBytes(32)
encryptor.IV = pdb.GetBytes(16)
Using cs As New CryptoStream(InputStream, encryptor.CreateDecryptor(), CryptoStreamMode.Read)
While (Assign(data, cs.ReadByte())) <> -1
outputStream.WriteByte(CByte(data))
Return outputStream.GetBuffer
Private Function Assign(Of T)(ByRef source As T, ByVal value As T) As T