using System.Security.Cryptography;
public class Encrypt_Decrypt
private static byte[] salt = Encoding.ASCII.GetBytes("CheckMarkInc");
private static string HashAlgorithm = "SHA1";
private static int passworditerations = 2;
private static byte[] iv = Encoding.ASCII.GetBytes("HR$2pIjHR$2pIj12");
private static int keysize = 256;
public static void Main()
Console.WriteLine("Crittare '{0}' produce: {1}", "bindhu", EncryptText("bindhu","checkmark"));
public static string EncryptText(String text,String paswrd){
if(string.IsNullOrEmpty(text)){
byte[] byte1 = System.Text.Encoding.UTF8.GetBytes(text);
byte[] byte2 = System.Text.Encoding.UTF8.GetBytes(paswrd);
byte[] inarray = Encrypt_Decrypt.AES_Encrypt(byte1, byte2);
string s = System.Convert.ToBase64String(inarray);
public static byte[] AES_Encrypt(byte[] inputtextbytes, byte[] paswrdbytes){
PasswordDeriveBytes pdb = new PasswordDeriveBytes(paswrdbytes, salt);
byte[] bytes3 = pdb.GetBytes(32);
Console.WriteLine("ENCODED STRING IS:'{0}'", System.Convert.ToBase64String(bytes3));
Console.WriteLine ("key\t{0}", BitConverter.ToString (bytes3));
using (var rijndaelManaged =
new RijndaelManaged { Key = paswrdbytes, IV = iv, Mode = CipherMode.CBC })
using (var memoryStream = new MemoryStream())
using (var cryptoStream =
new CryptoStream(memoryStream,
rijndaelManaged.CreateEncryptor(paswrdbytes, iv),
using (var ws = new StreamWriter(cryptoStream))
ws.Write(inputtextbytes);
result = memoryStream.ToArray();
Console.WriteLine("RESULT IS: '{0}'", Convert.ToBase64String(result));