205 shaares
5 private links
5 private links
/*********/
/*********/
/*********/
// GenerateRandomBytes returns securely generated random bytes.
// It will return an error if the system's secure random
// number generator fails to function correctly, in which
// case the caller should not continue.
func GenerateRandomBytes(n int) ([]byte, error) {
b := make([]byte, n)
_, err := rand.Read(b)
// Note that err == nil only if we read len(b) bytes.
if err != nil {
return nil, err
}
return b, nil
}
// GenerateRandomString returns a URL-safe, base64 encoded
// securely generated random string.
// It will return an error if the system's secure random
// number generator fails to function correctly, in which
// case the caller should not continue.
func GenerateRandomString(s int) (string, error) {
b, err := GenerateRandomBytes(s)
return base64.URLEncoding.EncodeToString(b), err
}
/**************/
/*key, err := GenerateRandomBytes(32)
fmt.Printf("Key : %s", key)
k, err := fernet.DecodeKey(string(key))
/*if err != nil {
println("")
print("Error in DecodeKey")
println("")
fmt.Printf("key : %+v\n", key)
println("")
fmt.Printf("k : %+v\n", k)
println("")
panic(err)//change this?
}*/