1.39 CRYPT_RSA_PublicEncrypt Function

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

ParametersDescription
rsaPointer to context which saves state between calls.
outPointer to output buffer to store results.
outSzSize of output buffer.
inPointer to source buffer to be encrypted.
inSzSize of input buffer.
rngPointer 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);