Details about Rijndael can be found here: http://www.iaik.tugraz.at/research/krypto/AES/old/~rijmen/rijndael/
Private Sub Main()
Dim Key As New RijndaelManaged
Dim Buffer() As Byte
Dim PlainText As String
' Encrypt a string to a byte array.
Buffer = Encrypt("This is some plaintext!", Key)
Debug.Print "Encrypted data"
PrintBytes Buffer
Debug.Print
' Decrypt the byte array back to a string.
PlainText = Decrypt(Buffer, Key)
' Display the plaintext value to the console.
Debug.Print "Original data"
Debug.Print PlainText
End Sub
Private Sub PrintBytes(ByRef Bytes() As Byte)
Dim i As Long
For i = LBound(Bytes) To UBound(Bytes)
Debug.Print Object.ToString(Bytes(i), "X2"); " ";
Next
Debug.Print
End Sub
' Encrypt the string.
Private Function Encrypt(ByVal PlainText As String, ByVal Key As SymmetricAlgorithm) As Byte()
Dim Encryptor As ICryptoTransform
Dim Buffer() As Byte
Buffer = Encoding.UTF8.GetBytes(PlainText)
Set Encryptor = Key.CreateEncryptor
Encrypt = Encryptor.TransformFinalBlock(Buffer, 0, CorArray.Length(Buffer))
End Function
' Decrypt the byte array.
Public Function Decrypt(ByRef CypherText() As Byte, ByVal Key As SymmetricAlgorithm) As String
Dim Decryptor As ICryptoTransform
Dim Buffer() As Byte
Set Decryptor = Key.CreateDecryptor
Buffer = Decryptor.TransformFinalBlock(CypherText, 0, CorArray.Length(CypherText))
Decrypt = Encoding.UTF8.GetString(Buffer)
End Function
' This example produces the following output.
'
' Encrypted Data (may be different because key is generated)
' FA 5B 69 FB 30 48 B6 08 C3 68 4C 63 45 BE F9 FA 17 DC 4D B9 EC FC E7 84 3A 35 CB 41 1C 5E 1D E5
'
' Original Data
' This is some plaintext!