pub fn decrypt_bytes<S: AsRef<str>>(
encoded: S,
) -> Result<Zeroizing<Vec<u8>>, CryptoError>Expand description
Decrypt an encoded ciphertext string into raw bytes.
Accepts either:
v1:nonce_b64:ciphertext_b64(current)nonce_b64:ciphertext_b64(legacy)
§Key behavior
This function does not auto-initialize the key.
If the key is missing, it returns CryptoError::KeyNotSet.
§Example
use keycrypt::{encrypt_bytes, decrypt_bytes};
let enc = encrypt_bytes(b"hello")?;
let dec = decrypt_bytes(&enc)?;
assert_eq!(dec.as_slice(), b"hello");§Errors
CryptoError::InvalidFormatif the input format is wrong.CryptoError::InvalidNonceif nonce length is not 12 bytes.CryptoError::KeyNotSetif the key does not exist.CryptoError::DecryptionFailedif authentication fails (wrong key/tampering/AAD mismatch).