public static string Decrypt(string cyphertext, string password) { byte[] t = DecodeEncodeHelper.Hex2Bin(cyphertext); byte[] p = Encoding.UTF8.GetBytes(password); var iv = t.Take(16); byte[] ivb = iv.ToArray(); byte[] to = t.Skip(16).ToArray(); //DEBUG.Print("Crypto", "pass: "******"Crypto", "data: " + DecodeEncodeHelper.Bin2Hex(to)); return(_unpad(AES.Decrypt(to, p, ivb))); }
public static string Encrypt(string plaintext, string password) { byte[] p = Encoding.UTF8.GetBytes(password); byte[] iv = new byte[16]; rnd.NextBytes(iv); byte[] encrypted = AES.Encrypt(_pad(plaintext), p, iv); byte[] ivEnc = new byte[encrypted.Length + iv.Length]; Array.Copy(iv, ivEnc, iv.Length); Array.Copy(encrypted, 0, ivEnc, iv.Length, encrypted.Length); return(DecodeEncodeHelper.Bin2Hex(ivEnc)); }