Decrypting the Introductory Example

Step 3b: Setting the Key Object

We need to fill our key with the same 10 bytes of data we used for encryption. We must make sure that we use the same key as we used to encrypt. For our sample application, we can simply re-create the key data we had before:

static unsigned char rc4KeyData[] = {

0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10

};

Now we can complete the call to B_SetKeyInfo:

if ((status = B_SetKeyInfo

(rc4Key, KI_Item, (POINTER)&rc4KeyData)) != 0) break;

Step 4: Update

Here, we must set the buffer that will store the decrypted data; for the RC4 cipher, it should be the same size as the encrypted data’s buffer:

unsigned char *decryptedData = NULL_PTR;

decryptedData = T_malloc (encryptedDataLen);

if ((status = (decryptedData == NULL_PTR)) != 0) break;

if ((status = B_DecryptUpdate

(rc4Decrypter, decryptedData, &decryptedLenUpdate, encryptedDataLenTotal, encryptedData, outputLenTotal, (B_ALGORITHM_OBJ)NULL_PTR,

(A_SURRENDER_CTX *)NULL_PTR)) != 0) break;

C h a p t e r 2 Q u i c k S t a r t

2 7

Page 49
Image 49
RSA Security 5.2.2 manual Setting the Key Object, Now we can complete the call to BSetKeyInfo