32 lines
570 B
Go
32 lines
570 B
Go
/* Generate 2factor secret for use
|
|
* with google authenticator (base32) an oathool (base16)
|
|
*/
|
|
package main
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/hex"
|
|
"encoding/base32"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
func randSecret() ([]byte, error) {
|
|
b := make([]byte, 20)
|
|
_, err := rand.Read(b)
|
|
if err != nil {
|
|
return b,err
|
|
}
|
|
return b,nil
|
|
}
|
|
|
|
func main() {
|
|
secret, _ := randSecret()
|
|
|
|
secretb16 := hex.EncodeToString(secret)
|
|
secretb32 := strings.ToUpper(base32.StdEncoding.EncodeToString(secret))
|
|
|
|
fmt.Printf("secret: %s\n", secretb16)
|
|
fmt.Printf("authenticator: %s\n", secretb32)
|
|
}
|