From f1ed621c9b95d6f34d5bfc60f26fefbfe35d36be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B0=E4=BA=AE?= Date: Thu, 10 Oct 2019 19:37:34 +0800 Subject: [PATCH] =?UTF-8?q?Add=20=E7=AD=BE=E5=90=8D=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/test/test.go | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 app/controller/test/test.go diff --git a/app/controller/test/test.go b/app/controller/test/test.go new file mode 100644 index 00000000..129f3320 --- /dev/null +++ b/app/controller/test/test.go @@ -0,0 +1,55 @@ +package test + +import ( + "fmt" + "github.com/gin-gonic/gin" + "go-gin-api/app/util" + "time" +) + +func Md5Test(c *gin.Context) { + startTime := time.Now() + appSecret := "IgkibX71IEf382PT" + encryptStr := "param_1=xxx¶m_2=xxx&ak=xxx&ts=1111111111" + count := 1000000 + for i := 0; i < count; i++ { + // 生成签名 + util.MD5(appSecret + encryptStr + appSecret) + + // 验证签名 + util.MD5(appSecret + encryptStr + appSecret) + } + utilGin := util.Gin{Ctx: c} + utilGin.Response(1, fmt.Sprintf("%v次 - %v", count, time.Since(startTime)), nil) +} + +func AesTest(c *gin.Context) { + startTime := time.Now() + appSecret := "IgkibX71IEf382PT" + encryptStr := "param_1=xxx¶m_2=xxx&ak=xxx&ts=1111111111" + count := 1000000 + for i := 0; i < count; i++ { + // 生成签名 + sn, _ := util.AesEncrypt(encryptStr, []byte(appSecret), appSecret) + + // 验证签名 + util.AesDecrypt(sn, []byte(appSecret), appSecret) + } + utilGin := util.Gin{Ctx: c} + utilGin.Response(1, fmt.Sprintf("%v次 - %v", count, time.Since(startTime)), nil) +} + +func RsaTest(c *gin.Context) { + startTime := time.Now() + encryptStr := "param_1=xxx¶m_2=xxx&ak=xxx&ts=1111111111" + count := 500 + for i := 0; i < count; i++ { + // 生成签名 + sn, _ := util.RsaPublicEncrypt(encryptStr, "rsa/public.pem") + + // 验证签名 + util.RsaPrivateDecrypt(sn, "rsa/private.pem") + } + utilGin := util.Gin{Ctx: c} + utilGin.Response(1, fmt.Sprintf("%v次 - %v", count, time.Since(startTime)), nil) +}