cmb
This commit is contained in:
parent
056004a0b2
commit
6ac3b3a4cd
|
|
@ -1,62 +0,0 @@
|
||||||
// Code generated by Wire. DO NOT EDIT.
|
|
||||||
|
|
||||||
//go:generate go run -mod=mod github.com/google/wire/cmd/wire
|
|
||||||
//go:build !wireinject
|
|
||||||
// +build !wireinject
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/go-kratos/kratos/v2"
|
|
||||||
"github.com/go-kratos/kratos/v2/log"
|
|
||||||
"voucher/internal/biz"
|
|
||||||
"voucher/internal/biz/cmb"
|
|
||||||
"voucher/internal/conf"
|
|
||||||
"voucher/internal/data"
|
|
||||||
"voucher/internal/data/mixrepoimpl"
|
|
||||||
"voucher/internal/data/repoimpl"
|
|
||||||
"voucher/internal/data/wechatrepoimpl"
|
|
||||||
log2 "voucher/internal/pkg/log"
|
|
||||||
"voucher/internal/server"
|
|
||||||
"voucher/internal/service"
|
|
||||||
)
|
|
||||||
|
|
||||||
import (
|
|
||||||
_ "go.uber.org/automaxprocs"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Injectors from wire.go:
|
|
||||||
|
|
||||||
// wireApp init kratos application.
|
|
||||||
func wireApp(bootstrap *conf.Bootstrap, logger log.Logger, accessLogger *log2.AccessLogger) (*kratos.App, func(), error) {
|
|
||||||
helper := log2.NewLogHelper(logger)
|
|
||||||
rdb, cleanup, err := data.NewRdb(bootstrap)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
orderRepo := repoimpl.NewOrderRepoImpl()
|
|
||||||
orderWechatRepo := repoimpl.NewOrderWechatRepoImpl()
|
|
||||||
productRepo := repoimpl.NewProductRepoImpl()
|
|
||||||
wechatCpnRepo, err := wechatrepoimpl.NewCpnRepoImpl(bootstrap)
|
|
||||||
if err != nil {
|
|
||||||
cleanup()
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
generateMixRepo := mixrepoimpl.NewGenerateMixRepoImpl(rdb)
|
|
||||||
cmbCmb := cmb.NewCmb(bootstrap, orderRepo, orderWechatRepo, productRepo, wechatCpnRepo, generateMixRepo)
|
|
||||||
rocketMQ, cleanup2, err := data.NewRocketMQ(bootstrap)
|
|
||||||
if err != nil {
|
|
||||||
cleanup()
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
mqSendMixRepo := mixrepoimpl.NewMQSendMixRepoImpl(rocketMQ)
|
|
||||||
voucherBiz := biz.NewVoucherBiz(bootstrap, rdb, cmbCmb, productRepo, orderRepo, mqSendMixRepo, wechatCpnRepo)
|
|
||||||
voucherService := service.NewVoucherService(bootstrap, voucherBiz)
|
|
||||||
httpServer := server.NewHTTPServer(bootstrap, helper, accessLogger, voucherService)
|
|
||||||
consumer := server.NewConsumer(helper, bootstrap, voucherService)
|
|
||||||
app := newApp(logger, httpServer, consumer)
|
|
||||||
return app, func() {
|
|
||||||
cleanup2()
|
|
||||||
cleanup()
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
@ -114,12 +114,11 @@ func decrypt(privateKey, inputJson string) (string, error) {
|
||||||
return string(Padding(plainText, 0)), nil
|
return string(Padding(plainText, 0)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func sign(privateKey, inputJson string) (string, error) {
|
func sign(privateKey, input string) (string, error) {
|
||||||
data, _ := base64.StdEncoding.DecodeString(inputJson)
|
|
||||||
|
|
||||||
signData, err := sm22.NewSm2().
|
signData, err := sm22.NewSm2().
|
||||||
SetHexPrivateKey(privateKey).
|
SetHexPrivateKey(privateKey).
|
||||||
SetData(data).
|
SetData([]byte(input)).
|
||||||
Sign().
|
Sign().
|
||||||
ToString()
|
ToString()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -128,12 +127,11 @@ func sign(privateKey, inputJson string) (string, error) {
|
||||||
return base64.StdEncoding.EncodeToString([]byte(signData)), nil
|
return base64.StdEncoding.EncodeToString([]byte(signData)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func verify(publicKey, inputJson, sign string) (bool, error) {
|
func verify(publicKey, input, sign string) (bool, error) {
|
||||||
data, _ := base64.StdEncoding.DecodeString(inputJson)
|
|
||||||
|
|
||||||
ok, err := sm22.NewSm2().
|
ok, err := sm22.NewSm2().
|
||||||
SetHexPublicKey(publicKey).
|
SetHexPublicKey(publicKey).
|
||||||
SetData(data).
|
SetData([]byte(input)).
|
||||||
SetBase64Signature(sign).
|
SetBase64Signature(sign).
|
||||||
Verify().
|
Verify().
|
||||||
ToBool()
|
ToBool()
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,10 @@ func TestGenerateSm2Key(t *testing.T) {
|
||||||
t.Log("SM2私钥:", got, len(got))
|
t.Log("SM2私钥:", got, len(got))
|
||||||
t.Log("SM2公钥:", got1, len(got1))
|
t.Log("SM2公钥:", got1, len(got1))
|
||||||
|
|
||||||
smbPrk := "a9106d11232db8ea5071c47c5f73c88668225438e61c1f81804016db75fac223"
|
smbPrk := "9450c673cf801164435b9c164ac1404e87997245bc6f323fde22015875a03f6e"
|
||||||
cmbPuk := "04a702106cf530dc981e44cd515b394747cfd6bb059247696b188b25281ea4278fe7c6e34a83680110eec71becd31f5db14abc671e5d8e67ce7ca3c6b3adc86674"
|
cmbPuk := "04a702106cf530dc981e44cd515b394747cfd6bb059247696b188b25281ea4278fe7c6e34a83680110eec71becd31f5db14abc671e5d8e67ce7ca3c6b3adc86674"
|
||||||
t.Log("SM2私钥:", smbPrk, len(smbPrk))
|
t.Log("掌上生活SM2私钥:", smbPrk, len(smbPrk))
|
||||||
t.Log("SM2公钥:", cmbPuk, len(cmbPuk))
|
t.Log("掌上生活SM2公钥:", cmbPuk, len(cmbPuk))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEncrypt(t *testing.T) {
|
func TestEncrypt(t *testing.T) {
|
||||||
|
|
@ -33,8 +33,8 @@ func TestDecrypt(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEncryptDecrypt(t *testing.T) {
|
func TestEncryptDecrypt(t *testing.T) {
|
||||||
priKey := "9450c673cf801164435b9c164ac1404e87997245bc6f323fde22015875a03f6e"
|
priKey := "44c33b565308062183ec53e7e9171eeab1a3f5df1f116bceb420f039eab469d4"
|
||||||
pukKey := "04a702106cf530dc981e44cd515b394747cfd6bb059247696b188b25281ea4278fe7c6e34a83680110eec71becd31f5db14abc671e5d8e67ce7ca3c6b3adc86674"
|
pukKey := "0479c4d66ffc74d5e0ff667d53da72f63f2c091cf4ee5fc3cc53142bc104dd68ffe332cf1151ce07e0cc62d64c9c7c3b5c94b161668d281691cab2424013eadfb2"
|
||||||
|
|
||||||
content := `{"name":"zhangxx","phoneNo":"137xxxxxxxx"}`
|
content := `{"name":"zhangxx","phoneNo":"137xxxxxxxx"}`
|
||||||
base64EncryptContent := base64.StdEncoding.EncodeToString([]byte(content))
|
base64EncryptContent := base64.StdEncoding.EncodeToString([]byte(content))
|
||||||
|
|
@ -56,18 +56,21 @@ func TestEncryptDecrypt(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSign(t *testing.T) {
|
func TestSign(t *testing.T) {
|
||||||
priKey := "E2C0860DAB46D3D2DBEF846450A1356B1F39E32F74770C165625E6822B2322F9"
|
priKey := "9450c673cf801164435b9c164ac1404e87997245bc6f323fde22015875a03f6e"
|
||||||
|
|
||||||
content := "accessToken.json?aid=9dad6d3900ec3ffabd80e46522a10ead&cmbKeyAlias=SM2_CMBLIFE&date=20240314091628&encryptBody=BNhquiza494xicGIOvE7G5jLr7nhQI6Tp4V5j3a+3P98oD+uUKVXAPXt+ae3GsDvs+FyOaqoNSzdYsSqNDW3rA1AFUbsljTI9EaWMB+FAHpZ3Wjn6Qyl8EzJpUIbCnqAIOWjr2hDsexJd+NPVxQwNqq9W66lC/PBC4/1/QCz+87Yq8b4hHx7bP2u5h95|YwTJn3uKMQfhDSuJKIx3hyFZcoLm9M2xKnVDmNLPq5PbGedoZY/4g1Z/sKk8cWzH&keyAlias=CO_PUB_KEY_SM2&mid=f806c259d86e3b9aa956c98d475b6af7&random=320bcb8c8cf7419e98d562439bdb3baa"
|
content := "accessToken.json?aid=9dad6d3900ec3ffabd80e46522a10ead&cmbKeyAlias=SM2_CMBLIFE&date=20240314091628&encryptBody=BNhquiza494xicGIOvE7G5jLr7nhQI6Tp4V5j3a+3P98oD+uUKVXAPXt+ae3GsDvs+FyOaqoNSzdYsSqNDW3rA1AFUbsljTI9EaWMB+FAHpZ3Wjn6Qyl8EzJpUIbCnqAIOWjr2hDsexJd+NPVxQwNqq9W66lC/PBC4/1/QCz+87Yq8b4hHx7bP2u5h95|YwTJn3uKMQfhDSuJKIx3hyFZcoLm9M2xKnVDmNLPq5PbGedoZY/4g1Z/sKk8cWzH&keyAlias=CO_PUB_KEY_SM2&mid=f806c259d86e3b9aa956c98d475b6af7&random=320bcb8c8cf7419e98d562439bdb3baa"
|
||||||
base64Content := base64.StdEncoding.EncodeToString([]byte(content))
|
|
||||||
xx, err := sign(priKey, base64Content)
|
xx, err := sign(priKey, content)
|
||||||
t.Log(xx, err)
|
t.Log(xx, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVerify(t *testing.T) {
|
func TestVerify(t *testing.T) {
|
||||||
priKey := "046E358B0EF1A12BEF28DF261DEF7FB7840037D9A1F5F6097DC8D5F8B036796558DA301220EB12C152FF3EC0B0A47DBAD9FA256446B070923B7CD17A6BAEAA45D7"
|
pukKey := "04838f74275e6f4f2373d4e6e974ac790c10ab6f9c17e273cf0c84848c6838979c158315932e36f0b9444442f145e4671b1ee5d43d5d63913a70d4d0d52cc3c0d6"
|
||||||
content := "accessToken.json?aid=9dad6d3900ec3ffabd80e46522a10ead&cmbKeyAlias=SM2_CMBLIFE&date=20240314091628&encryptBody=BNhquiza494xicGIOvE7G5jLr7nhQI6Tp4V5j3a+3P98oD+uUKVXAPXt+ae3GsDvs+FyOaqoNSzdYsSqNDW3rA1AFUbsljTI9EaWMB+FAHpZ3Wjn6Qyl8EzJpUIbCnqAIOWjr2hDsexJd+NPVxQwNqq9W66lC/PBC4/1/QCz+87Yq8b4hHx7bP2u5h95|YwTJn3uKMQfhDSuJKIx3hyFZcoLm9M2xKnVDmNLPq5PbGedoZY/4g1Z/sKk8cWzH&keyAlias=CO_PUB_KEY_SM2&mid=f806c259d86e3b9aa956c98d475b6af7&random=320bcb8c8cf7419e98d562439bdb3baa"
|
|
||||||
signDataBase64 := "MEQCIBI78ahUGpq7vE2pi48d79vUIKqld4jbPiCSg/UwZwv9AiB+d6DmFpPoGsRFUeY9pJd0fKujsXa8h8/wjEBoptd1Kg=="
|
content := "accessToken.json?aid=9dad6d3900ec3ffabd80e46522a10ead&cmbKeyAlias=SM2_CMBLIFE&date=20250305115032&encryptBody=BHeko/ZYFzQOJn6Q3y46X1AjNz8Nh5fq1FfMuWebh+TangLnlK5iFqePCst4rjG/FKJInijiKO2Qq18sJULlMEEgri05s+bHHDKM+Y+73crAbCnIhHbZxUjt8A0cq2rKjzkl8bxW33dU18uuiTEAmsAvKvmZgE6zJ1eDyjFWefHEIFJaKCNY2cTQOInt|8UYFZFTkx0DovPhaWCbdBkAqbgGmegT14F5gwXLJ6G1uWdYNvX+i5QWAYUGtd8u9&keyAlias=CO_PUB_KEY_SM2&mid=f806c259d86e3b9aa956c98d475b6af7&random=286d97b1d8ed4bbf822b004470c92ae8"
|
||||||
base64Content := base64.StdEncoding.EncodeToString([]byte(content))
|
|
||||||
xx, err := verify(priKey, base64Content, signDataBase64)
|
signDataBase64 := "MEUCIAg1zxnKG+X8t/hlwEoyL/T33iKgle09S6bfb3eZh/FqAiEAxtK5TdGAo+JpK7JmL15tT4nlQyrUzC14flu0Tq+9Svo="
|
||||||
|
|
||||||
|
xx, err := verify(pukKey, content, signDataBase64)
|
||||||
t.Log(xx, err)
|
t.Log(xx, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,8 @@
|
||||||
package cmb
|
package cmb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func GenerateSM4Key() []byte {
|
func GenerateSM4Key() []byte {
|
||||||
|
|
@ -19,20 +15,6 @@ func GenerateSM4Key() []byte {
|
||||||
return buffer
|
return buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenAccessToken(token string) string {
|
|
||||||
if token != "" {
|
|
||||||
return token
|
|
||||||
}
|
|
||||||
now := time.Now()
|
|
||||||
return strings.ToUpper(Md5Hash(now.Format("2006A01B02CD15E04F05"), ""))
|
|
||||||
}
|
|
||||||
|
|
||||||
func Md5Hash(password, salt string) string {
|
|
||||||
m := md5.New()
|
|
||||||
m.Write([]byte(salt + password))
|
|
||||||
return hex.EncodeToString(m.Sum(nil))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetSM4IV 获取SM4的IV
|
// GetSM4IV 获取SM4的IV
|
||||||
func GetSM4IV() []byte {
|
func GetSM4IV() []byte {
|
||||||
return RandomBytes(16)
|
return RandomBytes(16)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue