constantoine / totp-rs

RFC-compliant TOTP implementation with ease of use as a goal and additionnal QoL features.
https://crates.io/crates/totp-rs
MIT License
169 stars 20 forks source link

Doesn't generate matching codes #33

Closed Taha-Firoz closed 2 years ago

Taha-Firoz commented 2 years ago

Hi I'm comparing the different totp libraries available on crates and I don't understand why pins generated from this crate while using SHA1 with the same secret key are different from the the google authenticator crate. The totp generated by the google authenticator crate matches those generated by my authenticator app.

    let totp = TOTP::new(
        Algorithm::SHA1,
        6,
        1,
        30,
        Secret::Raw("I3VFM3JKMNDJCDH5BMBEEQAW6KJ6NOE3".as_bytes().to_vec()).to_bytes().unwrap(),
    ).unwrap();
    let code = totp.generate_current().unwrap();
    println!("Totp-rs {code}");
Taha-Firoz commented 2 years ago

Oops sorry didn't notice my key was encoded instead of being raw! Its good now