///AES Encryption/// </summary> /// <param name= "Inputdata" >the data entered</param> /// <param name= "IV" >Vector 128 bit</param> /// <param name= "Strkey" >encryption Key</param> /// <returns></returns> Public Static byte[] Aesencrypt (byte[] Inputdata,byte[] IV,stringstrkey) { //Packet Encryption AlgorithmSymmetricAlgorithm des =rijndael.create (); byte[] Inputbytearray = Inputdata;//get an array of bytes that need to be encrypted//set key and key vectorsDes. Key = Encoding.UTF8.GetBytes (strkey.substring (0, +)); Des.iv=IV; using(MemoryStream ms =NewMemoryStream ()) { using(CryptoStream cs =NewCryptoStream (MS, Des. CreateEncryptor (), cryptostreammode.write)) {cs. Write (Inputbytearray,0, inputbytearray.length); Cs. FlushFinalBlock (); byte[] Cipherbytes = Ms. ToArray ();//an array of bytes that have been encryptedcs. Close (); Ms. Close (); returncipherbytes; } } } /// <summary> ///AES Decryption/// </summary> /// <param name= "Inputdata" >the data entered</param> /// <param name= "IV" >Vector</param> /// <param name= "Strkey" >Key</param> /// <returns></returns> Public Static byte[] Aesdecrypt (byte[] Inputdata,byte[] IV,stringstrkey) {SymmetricAlgorithm des=rijndael.create (); Des. Key= Encoding.UTF8.GetBytes (Strkey.substring (0, +)); Des.iv=IV; byte[] Decryptbytes =New byte[Inputdata. Length]; using(MemoryStream ms =NewMemoryStream (Inputdata)) { using(CryptoStream cs =NewCryptoStream (MS, Des. CreateDecryptor (), CryptoStreamMode.Read)) {cs. Read (Decryptbytes,0, decryptbytes.length); Cs. Close (); Ms. Close (); } } returndecryptbytes; }
AES encryption and decryption in C #