fix(decrypt): 修复解密过程中的IV生成逻辑
This commit is contained in:
@@ -45,10 +45,16 @@ pub fn decrypt(data: String) -> Result<String, SpiralCipherError> {
|
||||
let data = data[1..].to_string();
|
||||
let key_seed = data[0..20].to_string();
|
||||
let key = gen_key(&key_seed);
|
||||
let iv: [u8; 16] = key[0..16].try_into().unwrap();
|
||||
let decryptor = AesDecryptor::new(&key.into(), &iv.into());
|
||||
|
||||
let encrypted_data = crate::serialize::from_base64_str(&data[20..])
|
||||
.map_err(|_| SpiralCipherError::CorruptedCipherData)?;
|
||||
|
||||
// 使用key的前16字节作为IV(与Go版本PrefixIVGenerator对应)
|
||||
let iv: [u8; 16] = key[0..16]
|
||||
.try_into()
|
||||
.map_err(|_| SpiralCipherError::CorruptedCipherData)?;
|
||||
|
||||
let decryptor = AesDecryptor::new(&key.into(), &iv.into());
|
||||
let decrypted_data = decryptor
|
||||
.decrypt_padded_vec_mut::<cipher::block_padding::Pkcs7>(encrypted_data.as_slice())
|
||||
.map_err(|e| {
|
||||
|
||||
Reference in New Issue
Block a user