diff --git a/base62json.go b/base62json.go index 6d955e2..1629e59 100644 --- a/base62json.go +++ b/base62json.go @@ -23,7 +23,7 @@ func init() { func GenerateProjectSecret(key, secret string) ([]byte, error) { appSecret := lo.FindUniques([]byte(secret)) - if len(appSecret) != 62 { + if len(secret) != 62 { return nil, fmt.Errorf("Invalid secret") } @@ -35,7 +35,7 @@ func GenerateProjectSecret(key, secret string) ([]byte, error) { } func SetCharacters(secret string) error { - if len(secret) != 64 { + if len(secret) != 62 { return fmt.Errorf("encoding alphabet is not 62-bytes long") } bs62 = base62.NewEncoding(secret) diff --git a/base62json_test.go b/base62json_test.go index 1d5ac6c..e4d38f8 100644 --- a/base62json_test.go +++ b/base62json_test.go @@ -41,7 +41,7 @@ func TestGenerateProjectSecret(t *testing.T) { // PrV4uZRqFHWOjkYIo07J1wdU6cDyXzh5Asi2xb3QMCNSmEvLl8pgetBGfnT9aK 加密后 // PrV4uZReFpWOjkYIoNCJ1wdU6cDyXzh5Asi2xb3QM70SmEvLl8HgqtBGfnT9aK - res, _ := GenerateProjectSecret("demo", "PrV4uZReFpWOjkYIoNCJ1wdU6cDyXzh5Asi2xb3QM70SmEvLl8HgqtBGfnT9aK") + res, _ := GenerateProjectSecret("demo", "PrV4uZRqFHWOjkYIo07J1wdU6cDyXzh5Asi2xb3QMCNSmEvLl8pgetBGfnT9aK") t.Log(string(res)) res1, _ := GenerateProjectSecret("demo", "PrV4uZRqFHWOjkYIo07J1wdU6cDyXzh5Asi2xb3QMCNSmEvLl8pgetBGfnT9aK") @@ -50,3 +50,8 @@ func TestGenerateProjectSecret(t *testing.T) { // PrV4uZRqFHWOjkYIo07J1wdU6cDyXzh5Asi2xb3QMCNSmEvLl8pgetBGfnT9aK // PrV4uZReFpWOjkYIoNCJ1wdU6cDyXzh5Asi2xb3QM70SmEvLl8HgqtBGfnT9aK } + +func TestAlphabetEncode(t *testing.T) { + t.Log(SetCharacters("PrV4uZRqFHWOjkYIo07J1wdU6cDyXzh5Asi2xb3QMCNSmEvLl8pgetBGfnT9aK")) + t.Log(Encode(map[string]any{"isDebug": 1})) +}