if publicKey == nil {
if keyData, err := base64.StdEncoding.DecodeString(viper.GetString("keys.publicKey")); err != nil {
return false, err
} else {
if publicKey, err = x509.ReadPublicKeyFromHex(hex.EncodeToString(keyData)); err != nil {
return false, err
}
}
}
if signByte, err := base64.StdEncoding.DecodeString(signature); err != nil {
return false, err
} else {
hexString := hex.EncodeToString(signByte)
r, _ := new(big.Int).SetString(hexString[:64], 16)
s, _ := new(big.Int).SetString(hexString[64:], 16)
return sm2.Sm2Verify(publicKey, msg, []byte(viper.GetString("config.uid")), r, s), nil
}