fix rsa util
This commit is contained in:
parent
25f438237c
commit
2c43e758f5
@ -1,6 +1,7 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/rand"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
@ -22,9 +23,9 @@ func EncryptWithPublicKey(data string, pemBytes []byte) (string, error) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return "", errors.New("not RSA public key")
|
return "", errors.New("not RSA public key")
|
||||||
}
|
}
|
||||||
ciphertext, err := rsa.EncryptPKCS1v15(nil, pubKey, []byte(data))
|
ciphertext, err := rsa.EncryptPKCS1v15(rand.Reader, pubKey, []byte(data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return base64.StdEncoding.EncodeToString(ciphertext), nil
|
return base64.StdEncoding.EncodeToString(ciphertext), nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user