From aefd14e619da80176be337e972ce5c2a7560f347 Mon Sep 17 00:00:00 2001 From: learn Date: Fri, 19 May 2023 17:21:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=EF=BC=9A=E8=A7=A3=E5=AF=86?= =?UTF-8?q?=E4=B9=8B=E5=90=8E=E7=9A=84=E5=80=BC=20=20=E4=B8=8D=E7=AD=89?= =?UTF-8?q?=E4=BA=8E=20=E5=8A=A0=E5=AF=86=E5=89=8D=E7=9A=84=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gorsa.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/gorsa.go b/gorsa.go index 1d224e0..ec0012e 100644 --- a/gorsa.go +++ b/gorsa.go @@ -2,10 +2,9 @@ package gorsa import ( "encoding/base64" - "encoding/hex" ) -// 公钥加密 +// PublicEncrypt 公钥加密 func PublicEncrypt(data, publicKey string) (string, error) { grsa := RSASecurity{} @@ -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{} @@ -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 } // 私钥解密 @@ -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 }