using System.Security.Cryptography;
public static void Main()
Console.WriteLine("Hello World");
String strWillEncrypt = "itc111010brvs90v@8c93cc03be774fb390a58b92f5d76579@1234@1593679902";
String derivedKey = "cfb2b699a0de64d2b819cc8a42b90f69";
String encryptData = AesEncrypt(strWillEncrypt, derivedKey);
Console.WriteLine("strWillEncrypt.Length = {0}", strWillEncrypt.Length);
Console.WriteLine(encryptData);
public static String AesEncrypt(String str, String key)
if (string.IsNullOrEmpty(str)) return null;
Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
Byte[] theKey = HexStringToByteArray(key);
System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
Mode = System.Security.Cryptography.CipherMode.ECB,
Padding = System.Security.Cryptography.PaddingMode.PKCS7
System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor();
Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
String ret = bytesToHexStr(resultArray);
public static String bytesToHexStr(byte[] bytes)
char[] c = new char[bytes.Length * 2];
for(int bx = 0, cx = 0; bx < bytes.Length; ++bx, ++cx)
b = ((byte)(bytes[bx] >> 4));
c[cx] = (char)(b > 9 ? b + 0x37 + 0x20 : b + 0x30);
b = ((byte)(bytes[bx] & 0x0F));
c[++cx]=(char)(b > 9 ? b + 0x37 + 0x20 : b + 0x30);
public static byte[] HexStringToByteArray(String hex) {
return Enumerable.Range(0, hex.Length)
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))