goathlib

package module
v0.0.0-...-9ea8d1e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2019 License: MIT Imports: 7 Imported by: 1

README

goathlib

OTP generator library compatible with Google Authenticator.

Original code was taken from https://github.com/reedobrien/goathtool and then rewritten.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateHOTP

func GenerateHOTP(key []byte, counter int64) string

GenerateHOTP returns counter based code for given counter value.

Example
key, err := ParseSecret("GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ")
if err != nil {
	panic(err)
}
fmt.Println(GenerateHOTP(key, 0))
fmt.Println(GenerateHOTP(key, 1))
fmt.Println(GenerateHOTP(key, 2))
Output:

755224
287082
359152

func GenerateTOTP

func GenerateTOTP(key []byte, now time.Time) string

GenerateTOTP returns time based code for given time.

Example
// goathtool totp  -b -N "2005-03-18 01:58:29 UTC" 'gr6d 5br7 25s6 vnck v4vl hlao re'
key, err := ParseSecret("gr6d 5br7 25s6 vnck v4vl hlao re")
if err != nil {
	panic(err)
}
layout := "2006-01-02 15:04:05 MST"
timeStr := "2005-03-18 01:58:29 UTC"
t, err := time.Parse(layout, timeStr)
if err != nil {
	panic(err)
}
fmt.Println(GenerateTOTP(key, t))
Output:

018108

func ParseSecret

func ParseSecret(secret string) ([]byte, error)

ParseSecret parses OTP secret and returns a key that can be passed to GenerateHOTP and GenerateTOTP.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL