/// <summary> /// Decrypts a from encrypted bytes /// </summary> /// <param name="bytes"></param> /// <returns></returns> public static byte[] Decrypt(byte[] bytes) { ByteArrayBuilder result = new ByteArrayBuilder(); try { RijndaelManaged rijndael = InitRijndael(); ICryptoTransform decryptor = rijndael.CreateDecryptor(rijndael.Key, rijndael.IV); using (MemoryStream msDecrypt = new MemoryStream(bytes)) { using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) { using (BinaryReader srDecrypt = new BinaryReader(csDecrypt)) { // Read the decrypted bytes from the decrypting stream // and place them in a string. int readBytes = 0; do { byte[] buffer = new byte[READ_BUFFER_SIZE]; readBytes = srDecrypt.Read(buffer, 0, READ_BUFFER_SIZE); if (readBytes > 0) { result.AddChunkReference(buffer, readBytes); } }while (readBytes != 0); } } rijndael.Clear(); } } catch { }; return(result.ToArray()); }