internal static byte[] DecryptBytes(byte[] cipherText, string password) { // Check arguments. if (cipherText == null || cipherText.Length <= 0) throw new ArgumentNullException("cipherText"); byte[] decryptedBytes= new byte[cipherText.Length]; using (var rijAlg = new AesManaged { KeySize = 256, BlockSize = 128 }) { var key = new Rfc2898DeriveBytes(password, Encoding.UTF8.GetBytes(Salt)); rijAlg.Key = key.GetBytes(rijAlg.KeySize / 8); rijAlg.IV = key.GetBytes(rijAlg.BlockSize / 8); // Create a decrytor to perform the stream transform. ICryptoTransform decryptor = rijAlg.CreateDecryptor(rijAlg.Key, rijAlg.IV); // Create the streams used for decryption. using (var msDecrypt = new MemoryStream()) { using (var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Write)) { csDecrypt.Write(cipherText, 0, cipherText.Length); csDecrypt.FlushFinalBlock(); } decryptedBytes = msDecrypt.ToArray(); } } return decryptedBytes; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)