update go-util

This commit is contained in:
新亮
2019-11-16 07:59:18 +08:00
parent 2f47791dd9
commit 337acaa358
8 changed files with 16 additions and 16 deletions
+4 -4
View File
@@ -33,10 +33,10 @@ func AesTest(c *gin.Context) {
count := 1000000
for i := 0; i < count; i++ {
// 生成签名
sn, _ := aes.AesEncrypt(encryptStr, []byte(appSecret), appSecret)
sn, _ := aes.Encrypt(encryptStr, []byte(appSecret), appSecret)
// 验证签名
aes.AesDecrypt(sn, []byte(appSecret), appSecret)
aes.Decrypt(sn, []byte(appSecret), appSecret)
}
utilGin := response.Gin{Ctx: c}
utilGin.Response(1, fmt.Sprintf("%v次 - %v", count, time.Since(startTime)), nil)
@@ -48,10 +48,10 @@ func RsaTest(c *gin.Context) {
count := 500
for i := 0; i < count; i++ {
// 生成签名
sn, _ := rsa.RsaPublicEncrypt(encryptStr, "rsa/public.pem")
sn, _ := rsa.PublicEncrypt(encryptStr, "rsa/public.pem")
// 验证签名
rsa.RsaPrivateDecrypt(sn, "rsa/private.pem")
rsa.PrivateDecrypt(sn, "rsa/private.pem")
}
utilGin := response.Gin{Ctx: c}
utilGin.Response(1, fmt.Sprintf("%v次 - %v", count, time.Since(startTime)), nil)
+2 -2
View File
@@ -87,7 +87,7 @@ func verifySign(c *gin.Context) (map[string]string, error) {
return nil, errors.New("sn Error")
}
decryptStr, decryptErr := aes.AesDecrypt(sn, []byte(AppSecret), AppSecret)
decryptStr, decryptErr := aes.Decrypt(sn, []byte(AppSecret), AppSecret)
if decryptErr != nil {
return nil, errors.New(decryptErr.Error())
}
@@ -99,7 +99,7 @@ func verifySign(c *gin.Context) (map[string]string, error) {
// 创建签名
func createSign(params url.Values) (string, error) {
return aes.AesEncrypt(createEncryptStr(params), []byte(AppSecret), AppSecret)
return aes.Encrypt(createEncryptStr(params), []byte(AppSecret), AppSecret)
}
func createEncryptStr(params url.Values) string {
+2 -2
View File
@@ -87,7 +87,7 @@ func verifySign(c *gin.Context) (map[string]string, error) {
return nil, errors.New("sn Error")
}
decryptStr, decryptErr := rsa.RsaPrivateDecrypt(sn, config.AppRsaPrivateFile)
decryptStr, decryptErr := rsa.PrivateDecrypt(sn, config.AppRsaPrivateFile)
if decryptErr != nil {
return nil, errors.New(decryptErr.Error())
}
@@ -99,7 +99,7 @@ func verifySign(c *gin.Context) (map[string]string, error) {
// 创建签名
func createSign(params url.Values) (string, error) {
return rsa.RsaPublicEncrypt(createEncryptStr(params), AppSecret)
return rsa.PublicEncrypt(createEncryptStr(params), AppSecret)
}
func createEncryptStr(params url.Values) string {
+1 -1
View File
@@ -16,7 +16,7 @@ require (
github.com/uber-go/atomic v1.4.0 // indirect
github.com/uber/jaeger-client-go v2.18.1+incompatible
github.com/uber/jaeger-lib v2.1.1+incompatible // indirect
github.com/xinliangnote/go-util v0.0.0-20191109055458-c8d858c8d8b9
github.com/xinliangnote/go-util v0.0.0-20191115235314-e7d1576d41db
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0
google.golang.org/grpc v1.23.1
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
+2 -2
View File
@@ -66,8 +66,8 @@ github.com/uber/jaeger-lib v2.1.1+incompatible h1:VY/6p2WopO09BPnw787RbaCIlfKbCR
github.com/uber/jaeger-lib v2.1.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U=
github.com/ugorji/go v1.1.4 h1:j4s+tAvLfL3bZyefP2SEWmhBzmuIlH/eqNuPdFPgngw=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/xinliangnote/go-util v0.0.0-20191109055458-c8d858c8d8b9 h1:MoyZSQWPGWmLE8R5nIEUlxoxwaDYlz34Zh2K5QLgoKw=
github.com/xinliangnote/go-util v0.0.0-20191109055458-c8d858c8d8b9/go.mod h1:3ZornrplU9tYj9ar9jchik1XPQ10ZbSXkbgxXR5PVaU=
github.com/xinliangnote/go-util v0.0.0-20191115235314-e7d1576d41db h1:yReVDmqk6oBUOcSRUofahYHJlIwr7wrJ8yx1Ymkz84E=
github.com/xinliangnote/go-util v0.0.0-20191115235314-e7d1576d41db/go.mod h1:3ZornrplU9tYj9ar9jchik1XPQ10ZbSXkbgxXR5PVaU=
go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
+2 -2
View File
@@ -8,7 +8,7 @@ import (
)
// 加密 aes_128_cbc
func AesEncrypt (encryptStr string, key []byte, iv string) (string, error) {
func Encrypt (encryptStr string, key []byte, iv string) (string, error) {
encryptBytes := []byte(encryptStr)
block, err := aes.NewCipher(key)
if err != nil {
@@ -25,7 +25,7 @@ func AesEncrypt (encryptStr string, key []byte, iv string) (string, error) {
}
// 解密
func AesDecrypt (decryptStr string, key []byte, iv string) (string, error) {
func Decrypt (decryptStr string, key []byte, iv string) (string, error) {
decryptBytes, err := base64.URLEncoding.DecodeString(decryptStr)
if err != nil {
return "", err
+2 -2
View File
@@ -10,7 +10,7 @@ import (
)
// 公钥加密
func RsaPublicEncrypt(encryptStr string, path string) (string, error) {
func PublicEncrypt(encryptStr string, path string) (string, error) {
// 打开文件
file, err := os.Open(path)
if err != nil {
@@ -46,7 +46,7 @@ func RsaPublicEncrypt(encryptStr string, path string) (string, error) {
}
// 私钥解密
func RsaPrivateDecrypt(decryptStr string, path string) (string, error) {
func PrivateDecrypt(decryptStr string, path string) (string, error) {
// 打开文件
file, err := os.Open(path)
if err != nil {
+1 -1
View File
@@ -60,7 +60,7 @@ github.com/uber/jaeger-client-go/thrift-gen/baggage
github.com/uber/jaeger-lib/metrics
# github.com/ugorji/go v1.1.4
github.com/ugorji/go/codec
# github.com/xinliangnote/go-util v0.0.0-20191109055458-c8d858c8d8b9
# github.com/xinliangnote/go-util v0.0.0-20191115235314-e7d1576d41db
github.com/xinliangnote/go-util/aes
github.com/xinliangnote/go-util/md5
github.com/xinliangnote/go-util/rsa