@@ 5,10 5,10 @@ import (
"crypto/cipher"
"crypto/rand"
"encoding/base64"
- "encoding/binary"
"errors"
"io"
mrand "math/rand"
+ "time"
)
// ErrInvalidValue ...
@@ 37,17 37,11 @@ type KeyWallet struct {
func GenerateKey(keylen int, alpha bool) []byte {
key := make([]byte, keylen)
if alpha {
- var seed [8]byte
- _, err := rand.Read(seed[:])
- if err != nil {
- // XXX Panic?
- panic("cannot seed cryptographically secure random number generator")
- }
- mrand.Seed(int64(binary.LittleEndian.Uint64(seed[:])))
+ r := mrand.New(mrand.NewSource(time.Now().UnixNano()))
chars := `abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ0123456789!@#$%^&*()-_=+[]{}\\|'";:/?.>,<`
for i := 0; i < keylen; i++ {
- key[i] = chars[mrand.Intn(len(chars))]
+ key[i] = chars[r.Intn(len(chars))]
}
return key
}