package RsaUtil import ( "crypto/rand" "crypto/rsa" "crypto/x509" "dsSdsf/Utils/ConfigUtil" "encoding/pem" "fmt" "github.com/pkg/errors" ) /** 功能:对前端的RSA加密进行解密 作者:黄海 时间:2020-02-24 */ func RsaDecrypt(ciphertext []byte) ([]byte, error) { privateKey := ConfigUtil.PrivateKey block, _ := pem.Decode([]byte(privateKey)) if block == nil { return nil, errors.New("private key error!") } priv, err := x509.ParsePKCS1PrivateKey(block.Bytes) if err != nil { return nil, errors.Wrap(err, fmt.Sprintf("Parse private key error:%s", err)) } return rsa.DecryptPKCS1v15(rand.Reader, priv, ciphertext) }