mirror of
https://github.com/kristoferssolo/cipher-workshop.git
synced 2026-02-04 06:42:11 +00:00
feat(aes-cbc): embed IV in encrypted output
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user