Link Search Menu Expand Document

6.1 Public Key Encryption


Encrypt the plaintext using RSA-OEAP.


Data Types

PKEEncKey
The RSA public key for public-key encryption with RSA.
PKEDecKey
The RSA private key, used for decryption.

Functions

PKEKeyGen() (PKEEncKey, PKEDecKey, error)

Generate a 256-byte RSA key pair for public-key encryption.


PKEEnc(ek PKEEncKey, plaintext []byte) (ciphertext []byte, err error)

Use the RSA public key to encrypt a message.

Parameters
ek (PKEEncKey) - RSA encryption (public) key
plaintext ([]byte) - message to encrypt

Returns
ciphertext ([]byte), err (error)


PKEDec(dk PKEDecKey, ciphertext []byte) (plaintext []byte, err error)

Use the RSA private key to decrypt a ciphertext.

Parameters
dk (PKEDecKey) - RSA decryption (private) key
ciphertext ([]byte) - message to decrypt

Returns
plaintext ([]byte), err (error)

Warning: PKEEnc does not support very long plaintext. Consider looking into hybrid encryption to communicate large payloads.