C# - AES Encrypt

input: string message, string keycode
output: string BASE64String

using System.Security.Cryptography;

RijndaelManaged aesCipher = new RijndaelManaged();
ASCIIEncoding textConverter = new ASCIIEncoding();
Byte[] iv;
aesCipher.KeySize = 128;
aesCipher.BlockSize = 128;
aesCipher.Mode = CipherMode.ECB;
aesCipher.Padding = PaddingMode.Zeros;
aesCipher.Key = textConverter.GetBytes(keycode);

ICryptoTransform crypto = aesCipher.CreateEncryptor();
Byte[] toEncrypt = textConverter.GetBytes(messg);
Byte[] cipherText = crypto.TransformFinalBlock(toEncrypt, 0, toEncrypt.Length);
String base64Str = "";
base64Str = Convert.ToBase64String(cipherText);

Popular posts from this blog

SAP CPI - Loop Process Call with SuccessFactor (oData V2)

Setting IntelliJ IDEA to run Groovy Script

C# - BASE64 to Image