21 lines
600 B
Rust
21 lines
600 B
Rust
use crate::bytes::Bytes;
|
|
use openssl::symm;
|
|
|
|
pub fn encrypt(Bytes(key): &Bytes, Bytes(data): &Bytes) -> Bytes {
|
|
let cipher = symm::Cipher::aes_128_ecb();
|
|
let data = symm::encrypt(cipher, key, None, data);
|
|
match data {
|
|
Ok(data) => Bytes(data),
|
|
Err(err) => panic!("{}", err.to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn decrypt(Bytes(key): &Bytes, Bytes(data): &Bytes) -> Bytes {
|
|
let cipher = symm::Cipher::aes_128_ecb();
|
|
let data = symm::decrypt(cipher, key, None, data);
|
|
match data {
|
|
Ok(data) => Bytes(data),
|
|
Err(err) => panic!("{}", err.to_string()),
|
|
}
|
|
}
|