Skip to content

Commit

Permalink
解决:解密之后的值 不等于 加密前的值
Browse files Browse the repository at this point in the history
  • Loading branch information
go-sniper committed May 19, 2023
1 parent d41f647 commit aefd14e
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions gorsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package gorsa

import (
"encoding/base64"
"encoding/hex"
)

// 公钥加密
// PublicEncrypt 公钥加密
func PublicEncrypt(data, publicKey string) (string, error) {

grsa := RSASecurity{}
Expand All @@ -19,7 +18,7 @@ func PublicEncrypt(data, publicKey string) (string, error) {
return base64.StdEncoding.EncodeToString(rsadata), nil
}

// 私钥加密
// PriKeyEncrypt 私钥加密
func PriKeyEncrypt(data, privateKey string) (string, error) {

grsa := RSASecurity{}
Expand All @@ -33,21 +32,22 @@ func PriKeyEncrypt(data, privateKey string) (string, error) {
return base64.StdEncoding.EncodeToString(rsadata), nil
}

// 公钥解密
// PublicDecrypt 公钥解密
func PublicDecrypt(data, publicKey string) (string, error) {

databs, _ := base64.StdEncoding.DecodeString(data)

grsa := RSASecurity{}
if err := grsa.SetPublicKey(publicKey);err !=nil{
return "",err
if err := grsa.SetPublicKey(publicKey); err != nil {
return "", err
}

rsadata, err := grsa.PubKeyDECRYPT(databs)
if err != nil {
return "", err
}
return hex.EncodeToString(rsadata),nil
//return hex.EncodeToString(rsadata),nil
return string(rsadata), nil
}

// 私钥解密
Expand All @@ -66,5 +66,6 @@ func PriKeyDecrypt(data, privateKey string) (string, error) {
return "", err
}

return hex.EncodeToString(rsadata), nil
//return hex.EncodeToString(rsadata), nil
return string(rsadata), nil
}

0 comments on commit aefd14e

Please sign in to comment.