otp
otp copied to clipboard
`HOTP::from_base32` does not support 16 chars.
Both github and M$ are using 16 chars base32 secret.
I tried to append \0
to the &[u8]
when using HOTP::from_bin
, still no luck.
Do you know how to fix it?
It sounds like the secret is in it's text form, from_bin
accepts the secret in it's binary form.
Try using HOTP::from_base32 on the textual secret.
Most services, including Github, MS, Google, etc... use TOTP. You may want to try using the totp
/validate_totp
functions...
If this doesn't resolve your issue, please attach a snippet of your code.
extern crate libotp;
use libotp::{HOTP, TOTP};
fn get_token(key: &str) -> String {
format!(
"{:06}",
TOTP::new(HOTP::from_base32(key).unwrap(), 30, 0).get_otp(6, 0)
)
}
fn main() {
println!("{}", get_token("AAA234567AABCDEF"))
}
As comparison to pyotp
python -c 'import pyotp; print(pyotp.TOTP("AAA234567AABCDEF").now())'
The problem is ring::hmac
does not support HMAC-MD5
in rust while python does:
python -c 'import hmac; print(hmac.new("AAA234567AABCDEF".encode("utf-8")).name)'
I have ported my code to python which works well.
If you don't want investigate on this, feel free to close this.