Function present::decrypt_str [] [src]

pub fn decrypt_str<K: Key>(ciphertext: &[u8], key: &K, mode: &OpMode, init_vec: Option<Block>) -> Result<StringDecryptError>

Decrypt a string.

Decrypt a string (given as a byte slice) using a specific key and operation mode. If decryption was successful, the decrypted string is returned, otherwise an error.

Arguments

Errors

Returns Err with a DecryptError if an error occurred during decryption. See the documentation of DecryptError for details.

Examples

use present::{encrypt_str, decrypt_str, Key80Bit, OpMode};
let key = Key80Bit::new([0xFF; 10]);
let op_mode = OpMode::CBC;
let (ciphertext, iv) = encrypt_str("Hello, world!", &key, &op_mode);

let decrypt_result = decrypt_str(&ciphertext, &key, &op_mode, iv);
assert_eq!(decrypt_result.unwrap(), "Hello, world!");Run