(length int)
| 157 | } |
| 158 | |
| 159 | func GenerateRandomCharsKey(length int) (string, error) { |
| 160 | b := make([]byte, length) |
| 161 | maxI := big.NewInt(int64(len(keyChars))) |
| 162 | |
| 163 | for i := range b { |
| 164 | n, err := crand.Int(crand.Reader, maxI) |
| 165 | if err != nil { |
| 166 | return "", err |
| 167 | } |
| 168 | b[i] = keyChars[n.Int64()] |
| 169 | } |
| 170 | |
| 171 | return string(b), nil |
| 172 | } |
| 173 | |
| 174 | func GenerateRandomKey(length int) (string, error) { |
| 175 | bytes := make([]byte, length*3/4) // 对于48位的输出,这里应该是36 |
no outgoing calls
no test coverage detected