pub fn decrypt(
    t: Cipher,
    key: &[u8],
    iv: Option<&[u8]>,
    data: &[u8]
) -> Result<Vec<u8>, ErrorStack>
Expand description

Decrypts data in one go, and returns the decrypted data.

Data is decrypted using the specified cipher type t in decrypt mode with the specified key and initialization vector iv. Padding is enabled.

This is a convenient interface to Crypter to decrypt all data in one go. To decrypt a stream of data incrementally , use Crypter instead.

Examples

Decrypt data in AES128 CBC mode

use openssl::symm::{decrypt, Cipher};

let cipher = Cipher::aes_128_cbc();
let data = b"\xB4\xB9\xE7\x30\xD6\xD6\xF7\xDE\x77\x3F\x1C\xFF\xB3\x3E\x44\x5A\x91\xD7\x27\x62\
             \x87\x4D\xFB\x3C\x5E\xC4\x59\x72\x4A\xF4\x7C\xA1";
let key = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F";
let iv = b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07";
let ciphertext = decrypt(
    cipher,
    key,
    Some(iv),
    data).unwrap();

assert_eq!(
    b"Some Crypto Text",
    &ciphertext[..]);