6 个稳定版本
2.0.1 | 2023年10月30日 |
---|---|
2.0.0 | 2022年5月20日 |
1.1.0 |
|
1.0.3 | 2021年5月28日 |
1.0.1 | 2020年8月21日 |
在 认证 中排名第 36
每月下载量 11,939 次
在 14 个Crate(9 个直接使用)中使用
11KB
130 代码行
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