How to use GO to implement RSA’s public key encryption and private key decryption

  golang, question

Not private key encryption public key decryption

import (
 "crypto/rand"
 "crypto/rsa"
 "crypto/x509"
 "encoding/pem"
 "errors"
 )
 
 //encryption
 func RsaEncrypt(publicKey []byte, origData []byte) ([]byte, error) {
 block, _ := pem.Decode(publicKey)
 if block == nil {
 return nil, errors.New("public key error")
 }
 pubInterface, err := x509.ParsePKIXPublicKey(block.Bytes)
 if err !  = nil {
 return nil, err
 }
 pub := pubInterface.(*rsa.PublicKey)
 return rsa.EncryptPKCS1v15(rand.Reader, pub, origData)
 }
 
 //Decrypt
 func RsaDecrypt(privateKey []byte, ciphertext []byte) ([]byte, error) {
 block, _ := pem.Decode(privateKey)
 if block == nil {
 return nil, errors.New("private key error!"  )
 }
 priv, err := x509.ParsePKCS1PrivateKey(block.Bytes)
 if err !  = nil {
 return nil, err
 }
 return rsa.DecryptPKCS1v15(rand.Reader, priv, ciphertext)
 }