' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
Imports System
Imports System.Text
Imports System.Security.Cryptography

Class MainClass
    Public Shared Sub Main(ByVal args As String())
        Dim utf As Encoding = New UTF8Encoding
        Dim aes As Rijndael = New RijndaelManaged
        Dim key As Byte() = utf.GetBytes("hemmeligabcdefgh12345678")
        Dim iv As Byte() =  {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
        Dim encrypt As ICryptoTransform = aes.CreateEncryptor(key, iv)
        Dim plain1 As String = "Dette er en lille test"
        Dim cipher As Byte() = encrypt.TransformFinalBlock(utf.GetBytes(plain1), 0, utf.GetByteCount(plain1))
        Dim i As Integer
        For i = 0 To cipher.Length-1
            Console.WriteLine(cipher(i))
        Next
        Dim decrypt As ICryptoTransform = aes.CreateDecryptor(key, iv)
        Dim plain2 As String = utf.GetString(decrypt.TransformFinalBlock(cipher, 0, cipher.Length))
        Console.WriteLine(plain2)
    End Sub
End Class 
