Sub Encrypt (s As String, key_val As String, iv_val As String)
Dim Bconv As ByteConverter
Dim B64 As Base64
Dim kg As KeyGenerator
Dim key(32), key1() As Byte
Dim data(0) As Byte
Dim iv(32), iv1() As Byte
iv1 = iv_val.GetBytes("ASCII")
Log(iv.Length)
Bconv.ArrayCopy(iv1, 0, iv, 0, iv1.Length)
Dim c As Cipher
c.Initialize("AES/CBC/PKCS5Padding") 'AES/CBC/PKCS5Padding replace "DES/" with "AES/" for Rijndael or "DESEDE/" for triple DES
' CBC needs an initialisation vector
Log(c.GetAlgorithms
c.InitialisationVector = iv
kg.Initialize("AES") ' replace "DES" with "AES" for Rijndael or "DESEDE" for triple DES
key1 = key_val.GetBytes("ASCII") 'ISO-8859-1
Bconv.ArrayCopy(key1, 0, key, 0, key1.Length)
kg.KeyFromBytes(key)
Log(Bconv.HexFromBytes(key) & " Key " & key.Length & " bytes")
data = Bconv.StringToBytes(s, "ASCII") 'ISO-8859-1
data = c.Encrypt(data, kg.key, True)
Dim res As String
res = B64.EncodeBtoS(data, 0, data.Length)
Log(res)
End Sub