// Encrypt encrypts a plain text represented as a byte array. The passed plain
// text MUST NOT be larger than the modulus of the passed public key.
Encrypt encrypts a plain text represented as a byte array. The passed plain
text MUST NOT be larger than the modulus of the passed public key.
// Encrypt encrypts a plain text represented as a byte array . The passed plain // text MUST NOT be larger than the modulus of the passed public key .
func Encrypt(pubKey *PublicKey, plainText []byte) ([]byte, error) {
	r, err := rand.Prime(rand.Reader, pubKey.N.BitLen())
	if err != nil {
		return nil, err
	}
	m := new(big.Int).SetBytes(plainText)
	if pubKey.N.Cmp(m) < 1 { 
		return nil, ErrMessageTooLong
	}
	n := pubKey.N
	c := new(big.Int).Mod(
		new(big.Int).Mul(
			new(big.Int).Exp(pubKey.G, m, pubKey.NSquared),
			new(big.Int).Exp(r, n, pubKey.NSquared),
		),
		pubKey.NSquared,
	)
	return c.Bytes(), nil
}
func Encrypt ( pubKey * PublicKey , plainText [ ] byte ) ( [ ] byte , error ) { r , err := rand . Prime ( rand . Reader , pubKey . N . BitLen ( ) ) if err != nil { return nil , err } m := new ( big . Int ) . SetBytes ( plainText ) if pubKey . N . Cmp ( m ) < 1 { return nil , ErrMessageTooLong } n := pubKey . N c := new ( big . Int ) . Mod ( new ( big . Int ) . Mul ( new ( big . Int ) . Exp ( pubKey . G , m , pubKey . NSquared ) , new ( big . Int ) . Exp ( r , n , pubKey . NSquared ) , ) , pubKey . NSquared , ) return c . Bytes ( ) , nil }
Encrypt encrypts a plain text represented as a byte array.
Encrypt encrypts a plain text represented as a byte array .
// N < m // c = g^m * r^n mod n^2