41 lines
842 B
Go
41 lines
842 B
Go
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,
|
|
})
|
|
}
|