Sub Encrypt(dataToEncrypt As String ) As String
Dim kg As KeyGenerator
Dim c As Cipher
Dim key(0) As Byte
Dim data(0) As Byte
Dim iv(0) As Byte
iv = "(=Lo78&@".GetBytes("ASCII") ' 16 bytes for AES
c.Initialize("DES/CBC/PKCS5Padding") ' replace "DES/" with "AES/" for Rijndael or "DESEDE/" for triple DES
' CBC needs an initialisation vector
c.InitialisationVector = iv
kg.Initialize("DES") ' replace "DES" with "AES" for Rijndael or "DESEDE" for triple DES
kg.KeyFromBytes(Bconv.StringToBytes("(=Lo78&@","ASCII"))
key = kg.KeyToBytes
Msgbox(Bconv.HexFromBytes(key), "Key " & key.Length & " bytes")
data = Bconv.StringToBytes(dataToEncrypt, "UTF8")
data = c.Encrypt(data, kg.key, True)
Msgbox(Bconv.HexFromBytes(data), "Encrypted is " & data.Length & " bytes")
Return
End Sub