Skip to content

Latest commit

 

History

History
62 lines (43 loc) · 1.51 KB

GUID-5F8144CD-63EE-4588-8582-17DA15D58CEA.md

File metadata and controls

62 lines (43 loc) · 1.51 KB

CRYPT_RSA_PublicEncrypt Function

Parent topic:MPLAB® Harmony Crypto Library

C

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
);

Description

This function encrypts a data block using a public key.

Preconditions

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

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.

Returns

  • BAD_FUNC_ARG - An invalid pointer was passed to the function.

  • int - Size of the actual output.

Remarks

None.

Example

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);