#openssl #password #key #salt #derive #evp-bytes-to-key

evpkdf

Rust 对 OpenSSL EVP_bytesToKey 函数的实现

3 个不稳定版本

0.2.0 2023 年 3 月 19 日
0.1.1 2021 年 10 月 7 日
0.1.0 2020 年 3 月 1 日

加密 中排名 1477

Download history 96/week @ 2024-03-16 195/week @ 2024-03-23 235/week @ 2024-03-30 170/week @ 2024-04-06 145/week @ 2024-04-13 192/week @ 2024-04-20 248/week @ 2024-04-27 249/week @ 2024-05-04 225/week @ 2024-05-11 123/week @ 2024-05-18 174/week @ 2024-05-25 116/week @ 2024-06-01 234/week @ 2024-06-08 415/week @ 2024-06-15 317/week @ 2024-06-22 318/week @ 2024-06-29

每月下载量 1,295
用于 9 crate(直接使用 2 个)

MIT 许可证

7KB

evpkdf

evpkdf 是 OpenSSL EVP_bytesToKey 函数的 Rust 实现。

evpkdf 从给定的密码和盐中派生密钥。

请注意,这种方法现在对于现代标准来说太弱了。新应用应选择更现代的算法,如 bcryptpbkdf2scrypt

基本用法

use evpkdf::evpkdf;
use hex_literal::hex;
use md5::Md5;   // from md-5 crate
use sha1::Sha1; // from sha-1 crate

let mut output = [];

evpkdf::<Md5>(b"password", b"saltsalt", 1000, &mut output);

assert_eq!(output, []);

let mut output = [0; 128 / 8];

evpkdf::<Md5>(b"password", b"saltsalt", 1000, &mut output);

assert_eq!(output, hex!("8006de5d2a5d15f9bbdb8f40196d5af1"));

let mut output = [0; 128 / 8];

evpkdf::<Sha1>(b"password", b"saltsalt", 1000, &mut output);

assert_eq!(output, hex!("f8833429b112582447bc66f433497f75"));

与 crypto-js 兼容

以下示例生成与 CryptoJS.kdf.OpenSSL.execute) 相同的结果。

use evpkdf::evpkdf;
use hex_literal::hex;
use md5::Md5;   // from md-5 crate

const KEY_SIZE: usize = 256;
const IV_SIZE: usize = 128;

let mut output = [0; (KEY_SIZE + IV_SIZE) / 8];

evpkdf::<Md5>(b"password", b"saltsalt", 1, &mut output);

let (key, iv) = output.split_at(KEY_SIZE / 8);

assert_eq!(
    key,
    hex!("fdbdf3419fff98bdb0241390f62a9db35f4aba29d77566377997314ebfc709f2")
);

assert_eq!(
    iv,
    hex!("0b5ca7b1081f94b1ac12e3c8ba87d05a")
);

许可证

MIT

依赖项

~330KB