Converting Data Between Binary and ASCII

Converting Data Between Binary and

ASCII

If you have data in binary format, yet need it in ASCII, or vice versa, Crypto-C offers functions to encode and decode according to the RFC1113 standard.

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

Encoding Binary Data To ASCII

Step 1: Creating An Algorithm Object

Declare a variable to be B_ALGORITHM_OBJ. As defined in the function prototype in Chapter 4 of the Reference Manual, its address is the argument for B_CreateAlgorithmObject:

B_ALGORITHM_OBJ asciiEncoder = (B_ALGORITHM_OBJ)NULL_PTR;

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

Step 2: Setting The Algorithm Object

There is only one ASCII encoding or decoding AI, AI_RFC1113Recode. The Reference Manual Chapter 2 entry for this AI states that the format of info supplied to B_SetAlgorithmInfo is NULL_PTR:

if ((status = B_SetAlgorithmInfo

(asciiEncoder, AI_RFC1113Recode, NULL_PTR)) != 0) break;

Step 3: Init

To initialize ASCII encoding, call B_EncodeInit. This function takes only one argument, the algorithm object:

1 7 2

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 194
Image 194
RSA Security 5.2.2 manual Encoding Binary Data To Ascii, Converting Data Between Binary and Ascii