Chapter 2 Quick Start 27
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:
Now we can complete the call to B_SetKeyInfo:
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 datas buffer:
static unsigned char rc4KeyData[] = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10
};
if ((status = B_SetKeyInfo
(rc4Key, KI_Item, (POINTER)&rc4KeyData)) != 0)
break;
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;