// TOTP implements the time-based one-time password algorithm with the suggested
// granularity of 30 seconds. See https://tools.ietf.org/html/rfc6238 and then
// https://tools.ietf.org/html/rfc4226#section-5.3

TOTP implements the time-based one-time password algorithm with the suggested
granularity of 30 seconds.
// TOTP implements the time - based one - time password algorithm with the suggested // granularity of 30 seconds . See https : // tools . ietf . org / html / rfc6238 and then // https : // tools . ietf . org / html / rfc4226#section - 5 . 3
func TOTP(secret []byte) string {
	const timeStep = 30
	now := uint64(time.Now().Unix()) / 30
	var nowBuf [8]byte
	binary.BigEndian.PutUint64(nowBuf[:], now)
	mac := hmac.New(sha256.New, secret)
	mac.Write(nowBuf[:])
	digest := mac.Sum(nil)
	value := binary.BigEndian.Uint32(digest[digest[31]&15:])
	value &= 0x7fffffff
	value %= 100000000
	return fmt.Sprintf("%08d", value)
}
func TOTP ( secret [ ] byte ) string { const timeStep = 30 now := uint64 ( time . Now ( ) . Unix ( ) ) / 30 var nowBuf [ 8 ] byte binary . BigEndian . PutUint64 ( nowBuf [ : ] , now ) mac := hmac . New ( sha256 . New , secret ) mac . Write ( nowBuf [ : ] ) digest := mac . Sum ( nil ) value := binary . BigEndian . Uint32 ( digest [ digest [ 31 ] & 15 : ] ) value &= 0x7fffffff value %= 100000000 return fmt . Sprintf ( " " , value ) }
TOTP implements the time-based one-time password algorithm with the suggested
granularity of 30 seconds.
TOTP implements the time - based one - time password algorithm with the suggested granularity of 30 seconds .