#totp #otp #2fa #hashing #sha-1

totp-lite

一个简单、正确的TOTP库

6 个稳定版本

2.0.1 2023年10月30日
2.0.0 2022年5月20日
1.1.0 2022年5月18日
1.0.3 2021年5月28日
1.0.1 2020年8月21日

认证 中排名第 36

Download history 3141/week @ 2024-04-27 3582/week @ 2024-05-04 3220/week @ 2024-05-11 3585/week @ 2024-05-18 3317/week @ 2024-05-25 3361/week @ 2024-06-01 2707/week @ 2024-06-08 3353/week @ 2024-06-15 2977/week @ 2024-06-22 2507/week @ 2024-06-29 3242/week @ 2024-07-06 2848/week @ 2024-07-13 2697/week @ 2024-07-20 3310/week @ 2024-07-27 2511/week @ 2024-08-03 3021/week @ 2024-08-10

每月下载量 11,939
14 个Crate(9 个直接使用)中使用

MIT 许可证

11KB
130 代码行

Workflow Status

totp-lite

一个简单、正确的TOTP库。

基于时间的单次密码(TOTP)是一种非常有用的客户端认证方式,因为有效的密码在攻击者可能猜测之前就已经过期。这个库提供了符合其规范RFC6238的TOTP实现,以及一个简单的接口。

用法

你可能需要的是 totp 函数。它使用默认的30秒时间步长,并生成8位输出。

use std::time::{SystemTime, UNIX_EPOCH};
use totp_lite::{totp, Sha512};

// Negotiated between you and the authenticating service.
let password: &[u8] = b"secret";

// The number of seconds since the Unix Epoch.
let seconds: u64 = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs();

// Specify the desired Hash algorithm via a type parameter.
// `Sha1` and `Sha256` are also available.
let result: String = totp::<Sha512>(password, seconds);
assert_eq!(8, result.len());

为了完全控制算法的配置,可以考虑使用 totp_custom

资源

许可证: MIT

依赖关系

~555KB
~12K SLoC