Converting Data Between Binary and ASCII

Step 5: Final

Finalize the encoding process, writing out any remaining bytes:

unsigned int asciiEncodingLenFinal;

if ((status = B_EncodeFinal

(asciiEncoder, asciiEncoding + asciiEncodingLenUpdate, &asciiEncodingLenFinal,

(binaryDataLen * 2) - asciiEncodingLenUpdate)) != 0) break;

Step 6: Destroy

Remember to destroy all objects and free up any memory allocated when done:

B_DestroyAlgorithmObject (&asciiEncoder);

T_free (asciiEncoding);

Decoding ASCII-Encoded Data

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 asciiDecoder = (B_ALGORITHM_OBJ)NULL_PTR;

if ((status = B_CreateAlgorithmObject (&asciiDecoder)) != 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 on this AI states that the format of info supplied to B_SetAlgorithmInfo is NULL_PTR:

1 7 4

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 196
Image 196
RSA Security 5.2.2 manual Decoding ASCII-Encoded Data, BDestroyAlgorithmObject &asciiEncoder Tfree asciiEncoding