mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-20 14:14:47 +01:00
Replace math rand with crypto rand
This commit is contained in:
19
lib/service/util.go
Normal file
19
lib/service/util.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
func randBytesFromStr(length int, from string) ([]byte, error) {
|
||||
b := make([]byte, length)
|
||||
fromLenBigInt := big.NewInt(int64(len(from)))
|
||||
for i := range b {
|
||||
r, err := rand.Int(rand.Reader, fromLenBigInt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b[i] = from[r.Int64()]
|
||||
}
|
||||
return b, nil
|
||||
}
|
||||
Reference in New Issue
Block a user