Decrypting the Introductory Example

Decrypting the Introductory Example

Decrypting data is similar to encrypting. The RC4 cipher uses symmetric-key encryption, which means the key that was used to encrypt will be the key needed for decryption.

The example in this section corresponds to the file dintroex.c.

Step 1: Creating an Algorithm Object

First create the algorithm object.

B_ALGORITHM_OBJ rc4Decrypter = (B_ALGORITHM_OBJ)NULL_PTR;

if ((status = B_CreateAlgorithmObject (&rc4Decrypter)) != 0) break;

Step 2: Setting the Algorithm Object

Use the same AI and parameters as for encryption:

if ((status = B_SetAlgorithmInfo (rc4Decrypter, AI_RC4, NULL_PTR)) != 0)

break;

Step 3: Init

Use the same key data as for encryption. Once again, we must create and set the key object.

Step 3a: Creating the Key Object

As before, we name our key object rc4Key and declare it as follows:

B_KEY_OBJ rc4Key = (B_KEY_OBJ)NULL_PTR;

Then we allocate space for the key object using B_CreateKeyObject:

if ((status = B_CreateKeyObject (&rc4Key)) != 0) break;

2 6

R S A B S A F E C r y p t o - C D e v e l o p e r ’s G u i d e

Page 48
Image 48
RSA Security 5.2.2 manual Decrypting the Introductory Example, Creating the Key Object, First create the algorithm object