func Decrypt(data []byte, key *rsa.PrivateKey) []byte {
	dec := gob.NewDecoder(bytes.NewReader(data))
	var ed encryptedData
	err := dec.Decode(&ed)
	if err != nil {
		panic(err)
	}
	symmetricKey := decryptAsymmetric(ed.EncryptedKey, key)
	decryptedPlaintext := decryptSymmetric(ed.Data, ed.NonceSize, symmetricKey)
	return decryptedPlaintext
}
Decrypt a byte array using the given private key. Returns the decrypted byte stream.
package main
import (
	"bytes"
	"crypto/aes"
	"crypto/cipher"
	"crypto/rand"
	"crypto/rsa"
	"crypto/sha256"
	"encoding/gob"
	"io"
	"log"
)
const keyLength = 32
var randReader = rand.Reader
type encryptedData struct {
	Data         []byte  
	EncryptedKey []byte  
	NonceSize    int     
}
func GenerateKey(bitSize int) (rsa.PublicKey, rsa.PrivateKey) {
	key, _ := rsa.GenerateKey(randReader, bitSize)
	pub := key.PublicKey
	return pub, *key
}
func Encrypt(data []byte, key *rsa.PublicKey) []byte {
	aesKey, nonceSize, data := encryptSymmetric(data)
	encryptedKey := encryptAsymmetric(aesKey, key)
	ed := encryptedData{data, encryptedKey, nonceSize}
	var buffer bytes.Buffer
	enc := gob.NewEncoder(&buffer)
	err := enc.Encode(ed)
	if err != nil {
		panic(err)
	}
	return buffer.Bytes()
}
func encryptSymmetric(message []byte) (symmetricKey []byte, nonceSize int, data []byte) {
	symmetricKey = newRandomKey(keyLength)
	gcm := createGCMEncryptionWithAES(symmetricKey)
	nonceSize = gcm.NonceSize()
	nonce := make([]byte, nonceSize)
	io.ReadFull(randReader, nonce)
	data = gcm.Seal(nonce, nonce, message, nil)
	return
}
func newRandomKey(keyLength int) []byte {
	key := make([]byte, keyLength)
	_, err := randReader.Read(key)
	if err != nil {
		panic(err)
	}
	return key
}
func encryptAsymmetric(message []byte, key *rsa.PublicKey) []byte {
	ciphertext, err := rsa.EncryptOAEP(sha256.New(), randReader, key, message, nil)
	if err != nil {
		panic(err)
	}
	return ciphertext
}