mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-12-01 06:46:50 +00:00
19 lines
367 B
Go
19 lines
367 B
Go
package generator
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/base64"
|
|
"errors"
|
|
)
|
|
|
|
func GenShadowsocksPassword(bits int) (string, error) {
|
|
if bits%8 != 0 {
|
|
return "", errors.New("bits must be multiple of 8")
|
|
}
|
|
password := make([]byte, bits/8)
|
|
if _, err := rand.Read(password); err != nil {
|
|
return "", err
|
|
}
|
|
return base64.StdEncoding.EncodeToString(password), nil
|
|
}
|