Dim Bconv As ByteConverter
Dim key(0) As Byte
Dim data(0) As Byte
Dim ivb(0) As Byte
Dim c As Cipher
Dim su As StringUtils
Dim privatekey2 As String = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 'I mask my privatekey
Dim pubkey() As Byte = su.DecodeBase64(privatekey2)
Dim publickey2 As String = "45eb2329869217a08c0858cc0d8bf81b4dc8df445e48e8a17e"
Dim privkey() As Byte = su.DecodeBase64(publickey2)
ivb= "xxxxxxxxxxxxxxxx".GetBytes("UTF8") 'Not the Real IV
Dim xdata = "HELLO CBC"
Dim xdatebyte() As Byte = su.DecodeBase64(xdata)
' use DES for variable length data using padding
Dim kg As KeyGenerator
Dim c As Cipher
'DESede/mpmp/PKCS5Padding
c.Initialize("DESEDE/CBC/PKCS5Padding") ' replace "DES/" with "AES/" for Rijndael or "DESEDE/" for triple DES
' CBC needs an initialisation vector
c.InitialisationVector = ivb
'Encrypt
kg.Initialize("DESede") ' replace "DES" with "AES" for Rijndael or "DESEDE" for triple DES
kg.KeyFromBytes(pubkey)
Dim data() As Byte
data= c.Encrypt(xdatebyte,kg.Key,True)
'Decrypt
kg.Initialize("DESede") ' replace "DES" with "AES" for Rijndael or "DESEDE" for triple DES
kg.KeyFromBytes(privkey)
Dim Ddata() As Byte
Ddata= c.Decrypt(data,kg.Key,True)