< 返回版块

donga-gao 发表于 2021-09-30 11:27

Tags:3DES-ECB

Rust中3DES-ECB的加解密库有哪些可用的,openssl里面找了个遍,没发现怎么用。有了解的吗?望告知一下!

评论区

写评论
Bai-Jinlin 2021-09-30 14:56

大概应该是这样,你和你用的对比一下。

use block_modes::block_padding::Pkcs7;
use block_modes::{BlockMode, Ecb};
use des::TdesEde2;
use hex_literal::hex;
type TdesEcb = Ecb<TdesEde2, Pkcs7>;

fn main() {
    let key = hex!("000102030405060708090a0b0c0d0e0f");
    let iv = hex!("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff");
    let plaintext = b"Hello world!";
    let cipher = TdesEcb::new_from_slices(&key, &iv).unwrap();

    let mut buffer = [0u8; 32];
    let pos = plaintext.len();
    buffer[..pos].copy_from_slice(plaintext);
    let ciphertext = cipher.encrypt(&mut buffer, pos).unwrap();
    println!("{:?}", ciphertext);
}
1 共 1 条评论, 1 页