You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
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 )
}