summaryrefslogtreecommitdiffstats
path: root/modules/base/tool.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/base/tool.go')
-rw-r--r--modules/base/tool.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/modules/base/tool.go b/modules/base/tool.go
index cb2eafd309..f4249f6d6d 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -12,6 +12,7 @@ import (
"encoding/hex"
"fmt"
"html/template"
+ "io"
"math"
"math/big"
"net/http"
@@ -103,6 +104,18 @@ func GetRandomString(n int) (string, error) {
return string(buffer), nil
}
+// GetRandomBytesAsBase64 generates a random base64 string from n bytes
+func GetRandomBytesAsBase64(n int) string {
+ bytes := make([]byte, 32)
+ _, err := io.ReadFull(rand.Reader, bytes)
+
+ if err != nil {
+ log.Fatal(4, "Error reading random bytes: %s", err)
+ }
+
+ return base64.RawURLEncoding.EncodeToString(bytes)
+}
+
func randomInt(max *big.Int) (int, error) {
rand, err := rand.Int(rand.Reader, max)
if err != nil {