68 lines
1.5 KiB
Go
68 lines
1.5 KiB
Go
|
package controller
|
||
|
|
||
|
import (
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"kefu/tools"
|
||
|
)
|
||
|
|
||
|
func GetAesEncrypt(c *gin.Context) {
|
||
|
key := c.Query("key")
|
||
|
content := c.Query("content")
|
||
|
res, err := tools.AesEncrypt([]byte(content), []byte(key))
|
||
|
res = []byte(tools.Base64Encode(string(res)))
|
||
|
if err != nil {
|
||
|
res = []byte(err.Error())
|
||
|
}
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 200,
|
||
|
"msg": "ok",
|
||
|
"result": string(res),
|
||
|
})
|
||
|
}
|
||
|
func GetAesDecrypt(c *gin.Context) {
|
||
|
key := c.Query("key")
|
||
|
content := c.Query("content")
|
||
|
decContent, _ := tools.Base64Decode2(content)
|
||
|
res, err := tools.AesDecrypt(decContent, []byte(key))
|
||
|
if err != nil {
|
||
|
res = []byte(err.Error())
|
||
|
}
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 200,
|
||
|
"msg": "ok",
|
||
|
"result": string(res),
|
||
|
})
|
||
|
}
|
||
|
func GetRsaEncrypt(c *gin.Context) {
|
||
|
publicKey := c.Query("publicKey")
|
||
|
privateKey := c.Query("privateKey")
|
||
|
rsa := tools.NewRsa(publicKey, privateKey)
|
||
|
content := c.Query("content")
|
||
|
res, err := rsa.Encrypt([]byte(content))
|
||
|
res = []byte(tools.Base64Encode(string(res)))
|
||
|
if err != nil {
|
||
|
res = []byte(err.Error())
|
||
|
}
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 200,
|
||
|
"msg": "ok",
|
||
|
"result": string(res),
|
||
|
})
|
||
|
}
|
||
|
func GetRsaDecrypt(c *gin.Context) {
|
||
|
publicKey := c.Query("publicKey")
|
||
|
privateKey := c.Query("privateKey")
|
||
|
rsa := tools.NewRsa(publicKey, privateKey)
|
||
|
content := c.Query("content")
|
||
|
decContent, _ := tools.Base64Decode2(content)
|
||
|
res, err := rsa.Decrypt([]byte(decContent))
|
||
|
if err != nil {
|
||
|
res = []byte(err.Error())
|
||
|
}
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 200,
|
||
|
"msg": "ok",
|
||
|
"result": string(res),
|
||
|
})
|
||
|
}
|