Skip to content

Commit a637776

Browse files
committed
Use rand.Reader directly instead of relying upon uuid
uuid did some bit manipulation so actually only guaranteed 122 bits of random data. This change gets us the full 128 bits.
1 parent 30b564f commit a637776

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

crypto/crypto.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
package crypto
22

33
import (
4+
"crypto/rand"
45
"encoding/base64"
6+
"io"
57
"strings"
6-
7-
"github.com/pborman/uuid"
88
)
99

1010
// SecureToken creates a new random token
1111
func SecureToken() string {
12-
token := uuid.NewRandom()
13-
return removePadding(base64.URLEncoding.EncodeToString([]byte(token)))
12+
b := make([]byte, 16)
13+
if _, err := io.ReadFull(rand.Reader, b); err != nil {
14+
panic(err.Error()) // rand should never fail
15+
}
16+
return removePadding(base64.URLEncoding.EncodeToString(b))
1417
}
1518

1619
func removePadding(token string) string {

0 commit comments

Comments
 (0)