feat: web frontend; middleware; serde (WIP?)
This commit is contained in:
@@ -63,9 +63,13 @@ pub fn encrypt(plaintext: &str, key: &str, iv: &str) -> Result<String, CryptoErr
|
||||
let encryptor = Aes128CbcEnc::new_from_slices(key_bytes, iv_bytes).map_err(CryptoError::Aes)?;
|
||||
|
||||
// 2. Encrypt the plaintext with PKCS7 padding
|
||||
let mut buffer = plaintext.as_bytes().to_vec();
|
||||
// Allocate buffer with extra space for padding (AES block size is 16 bytes)
|
||||
let plaintext_bytes = plaintext.as_bytes();
|
||||
let mut buffer = vec![0u8; plaintext_bytes.len() + 16];
|
||||
buffer[..plaintext_bytes.len()].copy_from_slice(plaintext_bytes);
|
||||
|
||||
let ciphertext = encryptor
|
||||
.encrypt_padded_mut::<Pkcs7>(&mut buffer, plaintext.len())
|
||||
.encrypt_padded_mut::<Pkcs7>(&mut buffer, plaintext_bytes.len())
|
||||
.map_err(CryptoError::Pad)?;
|
||||
|
||||
// 3. Base64 encode the ciphertext
|
||||
|
||||
Reference in New Issue
Block a user