AES encryption public byte[] Aesencrypt (string text) { byte[] data = Encoding.Unicode.GetBytes (text); SymmetricAlgorithm AES = Rijndael.create (); Aes. Key = Keyarray; AES.IV = Keyarray; Aes. Mode = CIPHERMODE.CBC; Aes. Padding = Paddingmode.zeros; using (MemoryStream ms = new MemoryStream ()) { using (CryptoStream cs = new CryptoStream (MS, AES). CreateEncryptor (), cryptostreammode.write)) { cs. Write (data, 0, data. Length); Cs. FlushFinalBlock (); Byte[] Cipherbytes = Ms. ToArray (); Gets the encrypted byte array of CS. Close (); Ms. Close (); Aes. Clear (); return cipherbytes;}} }
AES Decrypt public string Aesdecrypt (byte[] data) { SymmetricAlgorithm aes = Rijndael.create (); Aes. Key = Keyarray; AES.IV = Keyarray; Aes. Mode = CIPHERMODE.CBC; Aes. Padding = Paddingmode.zeros; byte[] decryptbytes = new Byte[data. Length]; using (MemoryStream ms = new MemoryStream (data)) { using (CryptoStream cs = new CryptoStream (MS, AES). CreateDecryptor (), cryptostreammode.read)) { cs. Read (decryptbytes, 0, decryptbytes.length); Cs. Close (); Ms. Close (); } } Aes. Clear (); Return System.Text.Encoding.Unicode.GetString (decryptbytes). Replace ("n", ""); }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
AES Encryption bit: 128-bit, encryption mode: CBC, fill mode: Zeros