aardio 文档

crypt.otp 库模块帮助文档

crypt.otp 成员列表 #

提供 HOTP (RFC 4226) 和 TOTP (RFC 6238) 一次性密码(One-Time Password)算法的生成与验证功能。
支持 sha1, sha256, sha512 哈希算法。

crypt.otp.generateSecret #

生成一个密码学安全的 Base32 编码密钥。
RFC 建议密钥长度至少为 16 字节(128位)

crypt.otp.generateSecret(length) #

可选使用参数 @length 指定密钥的字节长度,默认为 20。

crypt.otp.getUri #

生成 otpauth:// 格式 URI,用于身份验证器应用扫描二维码。
可使用 qrencode.bitmap 库转换为二维码图像。

crypt.otp.getUri(base32Secret,issuer,account,typ,digits=6, period=30,algorithm="sha1",counter) #

参数 @base32Secret: Base32 编码的密钥。
参数 @issuer) 服务提供商名称。
参数 @account) 用户账户名。
参数 @typ OTP 类型,"totp" 或 "hotp",默认为 "totp"。
其他参数用法与 hotp/totp 函数相同。

crypt.otp.hotp #

生成 HOTP (基于 HMAC 的一次性密码) - RFC 4226

crypt.otp.hotp(base32Secret,counter,digits=6,algorithm="sha1") #

参数 @base32Secret: Base32 编码的密钥。
参数 @counter: 计数器值。
参数 @digits: 密码位数,默认为 6。
参数 @algorithm: 哈希算法,可选 "sha1", "sha256", "sha512",默认为 "sha1"。

crypt.otp.totp #

生成 TOTP (基于时间的一次性密码) - RFC 6238。

crypt.otp.totp(base32Secret,period=30,digits=6,algorithm="sha1",t0=0) #

参数 @base32Secret: Base32 编码的密钥。
(period) 时间步长(秒),默认为 30。
参数 @digits: 密码位数,默认为 6。
参数 @algorithm: 哈希算法,可选 "sha1", "sha256", "sha512",默认为 "sha1"。
参数 @t0: 起始时间戳(Unix time),默认为 0。

返回 2 个值:动态密码,剩余秒数

Markdown 格式