kefu/controller/rsa.go

41 lines
842 B
Go
Raw Normal View History

2024-12-10 02:50:12 +00:00
package controller
import (
"crypto"
"github.com/gin-gonic/gin"
"kefu/tools"
)
//私钥签名
func GetSignRsa(c *gin.Context) {
//publicKey := c.PostForm("publicKey")
privateKey := c.PostForm("privateKey")
//rsa := tools.NewRsa(publicKey, privateKey)
content := c.PostForm("content")
res := tools.Rsa2PriSign(content, privateKey, crypto.SHA256)
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result": res,
})
}
//公钥验证签名
func PostCheckSignRsa(c *gin.Context) {
publicKey := c.PostForm("publicKey")
//privateKey := c.PostForm("privateKey")
sign := c.PostForm("sign")
source := c.PostForm("source")
res, err := tools.Rsa2PubCheckSign(source, sign, publicKey, crypto.SHA256)
msg := "ok"
if err != nil {
msg = err.Error()
}
c.JSON(200, gin.H{
"code": 200,
"msg": msg,
"result": res,
})
}