Sub EncryptAES(strDataToEncrypt As String, strKey As String) As String
Dim SU As StringUtils
Dim kg As KeyGenerator
Dim C As Cipher
Dim md As MessageDigest
Dim encrypted() As Byte
kg.Initialize("AES")
kg.KeyFromBytes(md.GetMessageDigest(strKey.GetBytes("UTF8"), "MD5"))
C.Initialize("AES/ECB/PKCS5Padding")
encrypted = C.Encrypt(strDataToEncrypt.GetBytes("UTF8"), kg.Key, False)
Return SU.EncodeBase64(encrypted)
End Sub
Sub DecryptAES(strDataToDecrypt As String, strKey As String) As String
Dim SU As StringUtils
Dim kg As KeyGenerator
Dim C As Cipher
Dim md As MessageDigest
Dim Decrypted() As Byte
kg.Initialize("AES")
kg.KeyFromBytes(md.GetMessageDigest(strKey.GetBytes("UTF8"), "MD5"))
C.Initialize("AES/ECB/PKCS5Padding")
Dim Bytes() As Byte = SU.DecodeBase64(strDataToDecrypt)
Decrypted = C.Decrypt(Bytes, kg.Key, False)
Return BytesToString(Decrypted, 0, Decrypted.Length, "UTF8")
End Sub