订单生成调整
This commit is contained in:
parent
8a389f04b0
commit
17bf37004f
|
|
@ -76,7 +76,8 @@ func Decrypt(privateKey, input string) (string, error) {
|
||||||
keyAndIvStr := tmpDataArr[0]
|
keyAndIvStr := tmpDataArr[0]
|
||||||
encryptedBody := tmpDataArr[1]
|
encryptedBody := tmpDataArr[1]
|
||||||
|
|
||||||
kvBase64Tmp, err := sm22.NewSm2().SetHexPrivateKey(privateKey).
|
kvBase64Tmp, err := sm22.NewSm2().
|
||||||
|
SetHexPrivateKey(privateKey).
|
||||||
SetBase64StringData(keyAndIvStr).
|
SetBase64StringData(keyAndIvStr).
|
||||||
SetSdk(sdk.NewCmbLifeSdk()).
|
SetSdk(sdk.NewCmbLifeSdk()).
|
||||||
SetCipherType(model.C1C3C2).
|
SetCipherType(model.C1C3C2).
|
||||||
|
|
@ -106,6 +107,9 @@ func Decrypt(privateKey, input string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
plainText, err := sm4.CBCDecrypt(plainKey, plainIv, data2)
|
plainText, err := sm4.CBCDecrypt(plainKey, plainIv, data2)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
return string(Padding(plainText, 0)), nil
|
return string(Padding(plainText, 0)), nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,9 +85,11 @@ func (s *Sm2) Encrypt() *Sm2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sm2) Decrypt() *Sm2 {
|
func (s *Sm2) Decrypt() *Sm2 {
|
||||||
|
|
||||||
if err := s.decryptErrHandler(); err != nil {
|
if err := s.decryptErrHandler(); err != nil {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
c1Len := 65
|
c1Len := 65
|
||||||
C1Byte := make([]byte, c1Len)
|
C1Byte := make([]byte, c1Len)
|
||||||
copy(C1Byte, s.data[:c1Len])
|
copy(C1Byte, s.data[:c1Len])
|
||||||
|
|
@ -125,16 +127,19 @@ func (s *Sm2) Verify() *Sm2 {
|
||||||
if err := s.encryptErrHandler(); err != nil {
|
if err := s.encryptErrHandler(); err != nil {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
c := s.publicKey.Curve
|
c := s.publicKey.Curve
|
||||||
N := c.Params().N
|
N := c.Params().N
|
||||||
if s.signature.R.Cmp(model.One) < 0 || s.signature.S.Cmp(model.One) < 0 {
|
if s.signature.R.Cmp(model.One) < 0 || s.signature.S.Cmp(model.One) < 0 {
|
||||||
s.toData = model.VerifyFalse
|
s.toData = model.VerifyFalse
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.signature.R.Cmp(N) >= 0 || s.signature.S.Cmp(N) >= 0 {
|
if s.signature.R.Cmp(N) >= 0 || s.signature.S.Cmp(N) >= 0 {
|
||||||
s.toData = model.VerifyFalse
|
s.toData = model.VerifyFalse
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
z := s.sdk.GetZ(s.publicKey.X, s.publicKey.Y, s.uid)
|
z := s.sdk.GetZ(s.publicKey.X, s.publicKey.Y, s.uid)
|
||||||
e := s.sdk.GetE(z, s.data)
|
e := s.sdk.GetE(z, s.data)
|
||||||
t := new(big.Int).Add(s.signature.R, s.signature.S)
|
t := new(big.Int).Add(s.signature.R, s.signature.S)
|
||||||
|
|
@ -143,6 +148,7 @@ func (s *Sm2) Verify() *Sm2 {
|
||||||
s.toData = model.VerifyFalse
|
s.toData = model.VerifyFalse
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
var x *big.Int
|
var x *big.Int
|
||||||
x1, y1 := c.ScalarBaseMult(s.signature.S.Bytes())
|
x1, y1 := c.ScalarBaseMult(s.signature.S.Bytes())
|
||||||
x2, y2 := c.ScalarMult(s.publicKey.X, s.publicKey.Y, t.Bytes())
|
x2, y2 := c.ScalarMult(s.publicKey.X, s.publicKey.Y, t.Bytes())
|
||||||
|
|
@ -155,6 +161,7 @@ func (s *Sm2) Verify() *Sm2 {
|
||||||
} else {
|
} else {
|
||||||
s.toData = model.VerifyFalse
|
s.toData = model.VerifyFalse
|
||||||
}
|
}
|
||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,14 +27,16 @@ func TestEncrypt(t *testing.T) {
|
||||||
func TestDecrypt(t *testing.T) {
|
func TestDecrypt(t *testing.T) {
|
||||||
priKey := "8d39ff3d2559258c163f4510f082727f51531e1953ab203d5ab1ea4a6d94fd73"
|
priKey := "8d39ff3d2559258c163f4510f082727f51531e1953ab203d5ab1ea4a6d94fd73"
|
||||||
|
|
||||||
content := "BKLjXVHHcGfZdbYrW/bERUghLv/hvnuEoYw0yRPWBpO2lysBlRLVg1cEh/TNqEgq3n2vlnDcXeXM2/OqfA0IL6e6CS4Nryu6c/RnlmTMxwYOSvklqUFLkqvIyYFhnhPnC2ABy7Tw36PZ/mzdyz8xgQjy8JMPsP3pgezI219fjFEe18UMUHnrhmd9+HUX|BZDXjwQpcWwYNd07vRnepgYK3WYAMaulhYU/3444JtuKNrHumF0C3P01GTpV3wNodx8CLB/21oabj9aPBySeiqrooVcQYCnfp6z0JEgl5wtk/KDSoom/EX9QdI0NSHLVrPxDk+c0ZjaSbmiQ9inNJlZ1lspBsLlzwcVQc0ibgaLaeaM8Z13+a0MipqFKOyCaGzsaSIt04AIbS9QMddNmA/LqNtR4JW7z04A//iBmv68="
|
//content := "BAdcIauIjNx3LsrplpJiZoljE4hCiGHra6ulhgG1qL0tKcAeenX+Z9VaHfXLSdkji1fYBpdZiiI35R0vFtnXPXJCJdHsGbfbae+PzNznYQS3KM8/90Y/FIWzSoszfUiF6fAuv8I6v9kQuqHUTidHeHyICDoyvJ0nhbNyUyg85bAKd6TmkVX1MgXLQ81m|5KfR/5UkpVBEQv1dx+iJbojOykNRuDV8Gsy3QOIlRI+cZvafRRPUUG6eeixnPMumhOvyZwsSG/OBeg0U/lSlAepg12tXWcQ601wjgyLaKN1iMvb1DCtfnJFAm8EWAc2SLH3NQuyhxGe/jgCXvj0wGphh4vBUzm8la8i8Aij0BI5lfgU5OzglkKDln6zHN3vBHDqOurEh18eU6z1bfvNnDpzdwEcygcEIH/6lGiqVnGH+C2+QpcKeCnj5qKGFiuSC"
|
||||||
|
content := "BDUuuPClIlUKDJdpHtNBIU6u5JTetrVG53AfKDSrhah9Q0QZWAj3K5pZF8G/HFtzj/KvbrHfP/gnHri0L7L91HaKYYc1vqy/q8Z69v7MEiIWL2LeLOsc2b0cHmnt7Qey5aZzYVbZJJNhus2gvhahGwOPpPL50JFC8IqAlU4+E/kUBgx+RgzAIkLLs8Se|k1WOt2Eb+xkxSobw/1DaLblguznhnsk1ga87sfqrrPATRuTyszzdVrRtCUuUHRKJ+vQwlZAR1ypkBC1vPMdt8zccI/CeNof+4Ap23enbQwTJQ4KRvij4kbJd6ycY97B+vHnI+oSnwfmjK0EWNUeRrCr2Uau7yxmzlFwJHprbgPZpHVuUjAzMIXNixOfxSTdc9dL+j3/tR7+yookvd9W3hNm96XZFPTheI0FqUKkbKWUUcVs4lC1/yEgjwXFcD4NM"
|
||||||
|
|
||||||
xx, err := Decrypt(priKey, content)
|
decryptStr, err := Decrypt(priKey, content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Log(err)
|
t.Log(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.Logf(xx)
|
|
||||||
|
t.Logf(decryptStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEncryptDecrypt(t *testing.T) {
|
func TestEncryptDecrypt(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,20 @@ import (
|
||||||
"voucher/internal/biz/vo"
|
"voucher/internal/biz/vo"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (s *VoucherService) readBody(bodyBytes []byte) (*v1.CmbRequest, error) {
|
||||||
|
|
||||||
|
var req *v1.CmbRequest
|
||||||
|
if err := json.Unmarshal(bodyBytes, &req); err != nil {
|
||||||
|
return nil, err2.ErrorCmbParamFail(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := req.Validate(); err != nil {
|
||||||
|
return nil, err2.ErrorCmbParamFail(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return req, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *VoucherService) CmbOrder(ctx http.Context) error {
|
func (s *VoucherService) CmbOrder(ctx http.Context) error {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -61,20 +75,6 @@ func (s *VoucherService) CmbOrder(ctx http.Context) error {
|
||||||
return ctx.JSON(200, reply)
|
return ctx.JSON(200, reply)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *VoucherService) readBody(bodyBytes []byte) (*v1.CmbRequest, error) {
|
|
||||||
|
|
||||||
var req *v1.CmbRequest
|
|
||||||
if err := json.Unmarshal(bodyBytes, &req); err != nil {
|
|
||||||
return nil, err2.ErrorCmbParamFail(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := req.Validate(); err != nil {
|
|
||||||
return nil, err2.ErrorCmbParamFail(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
return req, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *VoucherService) cmbOrder(ctx http.Context) (string, error) {
|
func (v *VoucherService) cmbOrder(ctx http.Context) (string, error) {
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(ctx.Request().Body)
|
bodyBytes, err := io.ReadAll(ctx.Request().Body)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue