RandLetterBytes returns a cryptographically secure random string with given length n
(n int)
| 52 | |
| 53 | // RandLetterBytes returns a cryptographically secure random string with given length n |
| 54 | func RandLetterBytes(n int) (string, errors.Error) { |
| 55 | if n < 0 { |
| 56 | return "", errors.Default.New("n must be greater than 0") |
| 57 | } |
| 58 | ret := make([]byte, n) |
| 59 | bi := big.NewInt(int64(len(letterBytes))) |
| 60 | for i := 0; i < n; i++ { |
| 61 | num, err := rand.Int(rand.Reader, bi) |
| 62 | if err != nil { |
| 63 | return "", errors.Convert(err) |
| 64 | } |
| 65 | ret[i] = letterBytes[num.Int64()] |
| 66 | } |
| 67 | |
| 68 | return string(ret), nil |
| 69 | } |
| 70 | |
| 71 | func SanitizeString(s string) string { |
| 72 | if s == "" { |