An one-time password generation library written in Go, implementing HOTP (RFC-4226) and TOTP (RFC-6238).
Simple 6-digit HOTP code:
import "onetime"
var secret = []byte("SOME_SECRET")
var counter = 123456
var otp, _ = onetime.Simple(6)
var code = otp.HOTP(secret, counter)
Google authenticator style 8-digit TOTP code:
import "onetime"
var secret = []byte("SOME_SECRET")
var otp, _ = onetime.Simple(8)
var code = otp.TOTP(secret)
9-digit 5-second-step TOTP starting on midnight 2000-01-01 UTC, using SHA-256:
import (
"crypto/sha256"
"onetime"
"time"
)
var secret = []byte("SOME_SECRET")
const ts = 5 * time.Second
var t = time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC)
var otp = onetime.OneTimePassword{Digit: 9, TimeStep: ts, BaseTime: t, Hash: sha256.New}
var code = otp.TOTP(secret)
Package doc can be found at godoc.org.
This library is released under a simplified BSD license.