Parent topic:MPLABĀ® Harmony Crypto Library
int CRYPT_RSA_PublicEncrypt(
    CRYPT_RSA_CTX* rsa, 
    unsigned char* out, 
    unsigned int outSz, 
    const unsigned char* in, 
    unsigned int inSz, 
    CRYPT_RNG_CTX* rng
);
This function encrypts a data block using a public key.
The context must be initialized using CRYPT_RSA_Initialize and the public key decoded using RYPT_RSA_PublicKeyDecode prior to calling this function. The random number generator must be initialized with a call to CRYPT_RNG_Initialize.
| Parameters | Description | 
|---|---|
| rsa | Pointer to context which saves state between calls. | 
| out | Pointer to output buffer to store results. | 
| outSz | Size of output buffer. | 
| in | Pointer to source buffer to be encrypted. | 
| inSz | Size of input buffer. | 
| rng | Pointer to Random Number Generator (RNG) context. | 
BAD_FUNC_ARG - An invalid pointer was passed to the function.
int - Size of the actual output.
None.
CRYPT_RSA_CTX mcRsa;
CRYPT_RNG_CTX mcRng;
int           ret;
unsigned int  keySz = (unsigned int)sizeof(client_key_der_1024);
byte          out1[256];
ret = CRYPT_RSA_Initialize(&mcRsa);
ret = CRYPT_RNG_Initialize(&mcRng);
ret = CRYPT_RSA_PublicKeyDecode(&mcRsa, client_key_der_1024, keySz);
ret = CRYPT_RSA_PublicEncrypt(&mcRsa, out1, sizeof(out1), ourData, RSA_TEST_SIZE, &mcRng);