TOTP in Go
一个很小的 TOTP 的实现 代码写的非常简洁易懂 代码注释已经说明了每一步的实现 package main import ( "crypto/hmac" "crypto/sha1" "encoding/base32" "encoding/binary" "fmt" "strings" "time" ) func generateTOTP(secretKey string, timestamp int64) uint32 { // The base32 encoded secret key string is decoded to a byte slice base32Decoder := base32.StdEncoding.WithPadding(base32.NoPadding) secretKey = strings.ToUpper(strings.TrimSpace(secretKey)) // preprocess secretBytes, _ := base32Decoder.DecodeString(secretKey) // decode // The truncated timestamp / 30 is converted to an 8-byte big-endian // unsigned integer slice timeBytes := make([]byte, 8) binary....