using System.Security.Cryptography;
string key = EncryptData("Hello World", "Lorem ipsum dolor sit amet, cons");
string akey = DecryptData("wgXgIU9XSBFYjJTo6qPc4Q==", "Lorem ipsum dolor sit amet, cons");
public string EncryptData(string textData, string Encryptionkey)
RijndaelManaged objrij = new RijndaelManaged();
objrij.Mode = CipherMode.CBC;
objrij.Padding = PaddingMode.PKCS7;
byte[] passBytes = Encoding.UTF8.GetBytes(Encryptionkey);
byte[] EncryptionkeyBytes = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
int len = passBytes.Length;
if (len > EncryptionkeyBytes.Length)
len = EncryptionkeyBytes.Length;
Array.Copy(passBytes, EncryptionkeyBytes, len);
objrij.Key = EncryptionkeyBytes;
objrij.IV = EncryptionkeyBytes;
ICryptoTransform objtransform = objrij.CreateEncryptor();
byte[] textDataByte = Encoding.UTF8.GetBytes(textData);
return Convert.ToBase64String(objtransform.TransformFinalBlock(textDataByte, 0, textDataByte.Length));
string DecryptData(string EncryptedText, string Encryptionkey)
RijndaelManaged objrij = new RijndaelManaged();
objrij.Mode = CipherMode.CBC;
objrij.Padding = PaddingMode.PKCS7;
byte[] encryptedTextByte = Convert.FromBase64String(EncryptedText);
byte[] passBytes = Encoding.UTF8.GetBytes(Encryptionkey);
byte[] EncryptionkeyBytes = new byte[0x10];
int len = passBytes.Length;
if (len > EncryptionkeyBytes.Length)
len = EncryptionkeyBytes.Length;
Array.Copy(passBytes, EncryptionkeyBytes, len);
objrij.Key = EncryptionkeyBytes;
objrij.IV = EncryptionkeyBytes;
byte[] TextByte = objrij.CreateDecryptor().TransformFinalBlock(encryptedTextByte, 0, encryptedTextByte.Length);
return Encoding.UTF8.GetString(TextByte);