...
1 package crypto
2
3 import (
4 "crypto/sha512"
5 "encoding/hex"
6
7 "edge-infra.dev/pkg/lib/crypto/randomizer"
8 )
9
10 var (
11 EdgeBootstrapTokenLength = 32
12 )
13
14 func GenerateRandomEdgeBootstrapToken() (Credential, error) {
15 token, err := randomizer.GenerateRandomBytes(EdgeBootstrapTokenLength)
16 if err != nil {
17 return sha512Credential{}, err
18 }
19 encodedTokenHex := hex.EncodeToString(token)
20 hashedPwd := HashEdgeBootstrapToken([]byte(encodedTokenHex))
21 return sha512Credential{plainTextPwd: encodedTokenHex, hashedPwd: hashedPwd, salt: []byte("")}, nil
22 }
23
24 func HashEdgeBootstrapToken(token []byte) []byte {
25 sha512Hasher := sha512.New()
26 sha512Hasher.Write(token)
27 return sha512Hasher.Sum(nil)
28 }
29
View as plain text