feat(aes-cbc): embed IV in encrypted output

This commit is contained in:
2026-01-11 20:24:16 +02:00
parent 8490e594ea
commit 6eb3668147
4 changed files with 75 additions and 54 deletions

View File

@@ -79,11 +79,15 @@ impl Algorithm {
/// Decrypts data using CBC mode and removes PKCS#7 padding.
///
/// The IV is extracted from the first 16 bytes of the ciphertext.
///
/// # Errors
///
/// Returns `CipherError` if decryption fails or padding is invalid.
pub fn decrypt_cbc(&self, key: &str, iv: &str, ciphertext: &[u8]) -> CipherResult<Vec<u8>> {
let cipher = self.new_cbc_cipher(key, iv)?;
pub fn decrypt_cbc(&self, key: &str, ciphertext: &[u8]) -> CipherResult<Vec<u8>> {
// IV is embedded in ciphertext, use dummy IV for cipher construction
let dummy_iv = "0x00000000000000000000000000000000";
let cipher = self.new_cbc_cipher(key, dummy_iv)?;
cipher.decrypt(ciphertext)
}