hu_RSAPKCS1v15Enc()

Encrypts a single plaintext block by applying the PKCS#1 v1.5 encryption scheme with an RSA public key.

Synopsis:

#include "hursa.h"
 
int hu_RSAPKCS1v15Enc(sb_Params rsaParams, sb_PublicKey publicKey, size_t plaintextLen, const unsigned char *plaintext, size_t *ciphertextLen, unsigned char *ciphertext, sb_GlobalCtx sbCtx)

Since:

BlackBerry 10.0.0

Arguments:

rsaParams

An RSA parameters object.

publicKey

An RSA public key object.

plaintextLen

The length (in bytes) of the plaintext. This must be at most the modulus length minus 11.

plaintext

The plaintext buffer.

ciphertextLen

The length (in bytes) of the ciphertext buffer. This must be at least the modulus length.

ciphertext

The ciphertext buffer.

sbCtx

A global context.

Library:

libhuapi (For the qcc command, use the -l huapi option to link against this library)

Description:

This function implements the operation known as RSAES-PKCS1-v1_5-Encrypt in PKCS#1 v2.1.

The RSA parameter object must have been created with an RNG context.

If the length of the ciphertext is known, a pointer to a buffer large enough to hold the ciphertext should be passed in ciphertext and its length in ciphertextLen. This function will copy the ciphertext into ciphertext and set the actual length of the ciphertext in ciphertextLen.

If ciphertext is NULL, then this function will set the correct length of the ciphertext value in ciphertextLen. If ciphertext is not NULL but ciphertextLen is too small, this function will return an error and also will set the correct length of the ciphertext value in ciphertextLen.

The length of the modulus can be determined by calling hu_RSAKeyGet() and retrieving the nLen argument.

Returns:

SB_ERR_NULL_PARAMS

The rsaParams object is NULL.

SB_ERR_BAD_PARAMS

The tag for the params object is not of the expected type.

SB_ERR_NULL_PUBLIC_KEY

The public key object is NULL.

SB_ERR_BAD_PUBLIC_KEY

The public key object is invalid.

SB_ERR_NULL_INPUT_BUF

The plaintext buffer is NULL.

SB_ERR_BAD_INPUT_BUF_LEN

The length of the plaintext is invalid.

SB_ERR_NULL_OUTPUT_BUF_LEN_PTR

The ciphertext buffer length is NULL.

SB_ERR_BAD_OUTPUT_BUF_LEN

The ciphertext buffer length is invalid.

SB_FAIL_ALLOC

Memory allocation failure.

SB_SUCCESS

Success.