Base 32 is the encoding, in which keys are given to Google Authenticator.
HELP: totp
{ $values
- { "key" byte-array }
+ { "key" object }
{ "string" string }
}
-{ $description "Generate a one-time password for the " { $snippet "key" } " based on the current system time. The " { $snippet "string" } " length is " { $link totp-digits } ", and the hash used for HMAC is " { $link totp-hash } "." } ;
+{ $description "Generate a one-time password for the " { $snippet "key" } " based on the current system time. If " { $snippet "key" } " is a " { $link string } ", it is expected to contain the key data in Base 32 encoding, otherwise it should be a " { $link byte-array } ". The " { $snippet "string" } " length is " { $link totp-digits } ", and the hash used for HMAC is " { $link totp-hash } "." } ;
{ totp totp* } related-words
! Copyright (C) 2018 Alexander Ilin.
! See http://factorcode.org/license.txt for BSD license.
-USING: calendar checksums.hmac checksums.sha io.binary kernel
-math math.bitwise math.parser namespaces sequences ;
+USING: base32 calendar checksums.hmac checksums.sha io.binary
+kernel math math.bitwise math.parser namespaces sequences
+strings unicode ;
IN: totp
SYMBOLS: totp-hash totp-digits ;
[ number>string ] dip [ CHAR: 0 pad-head ] keep tail* ;
: totp ( key -- string )
+ dup string? [ >upper base32> ] when
now timestamp>count swap totp-hash get totp* totp-digits get digits ;