From 96656afdae42a717a1c2e7d4ee092c90412ea1b6 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Mon, 21 Mar 2022 12:08:58 +0100 Subject: [PATCH] Managed to generate a first secret --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/main.rs | 8 ++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7456ad2..3aa9b27 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,6 +19,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "base32" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23ce669cd6c8588f79e15cf450314f9638f967fc5770ff1c7c1deb0925ea7cfa" + [[package]] name = "base64" version = "0.13.0" @@ -260,6 +266,7 @@ checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" name = "totp_generator" version = "0.1.0" dependencies = [ + "base32", "base64", "clap", "totp_rfc6238", diff --git a/Cargo.toml b/Cargo.toml index d47214b..56f95c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,5 @@ edition = "2018" [dependencies] totp_rfc6238 = "0.5.0" base64 = "0.13.0" +base32 = "0.4.0" clap = { version = "3.1.6", features = ["derive"] } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index a317bb8..43fbe60 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use base32::Alphabet; use clap::Parser; use totp_rfc6238::{HashAlgorithm, TotpGenerator}; @@ -27,8 +28,11 @@ fn main() { .set_hash_algorithm(HashAlgorithm::SHA1) .build(); - let key = base64::decode(args.secret).unwrap(); + let key = base32::decode( + Alphabet::RFC4648 { padding: true }, + &args.secret, + ).unwrap(); let code = totp_generator.get_code(&key); - println!("Secret len = {}", code); + println!("Secret = {}", code); }