
Chapter 2 Quick Start 9
Introductory Example
Introductory Example
The CD containing the Crypto-C library distribution also includes sample source code
to accompany this Developer’s Guide. One of the files on that CD,
introex.c, is an
example of converting the Introductory Example into a program. Later in this manual
are instructions on writing code for many Crypto-C operations. There are sample
programs on the CD to accompany all the topics covered.
With the RSA BSAFE Crypto-C Reference Manual handy, we will encrypt the sentence,
“Encrypt this sentence.” To do this, we will use what is called a stream cipher, that is,
an encryption method that encrypts data one character at a time, in a single stream.
The cipher we will use is called the RC4 cipher. This cipher can take a key size from 1
to 256 bytes. The RC4 cipher creates a “key stream” based on the key and XORs the
stream of data with the key stream to create ciphertext.
The example in this section corresponds to the file
introex.c.
Step 0: Include Files
You must include the following header file and the Crypto-C library in every
application you write using Crypto-C:
When writing a Crypto-C application, include
bsafe.h. If you want to use the
DEMO_ALGORITHM_CHOOSER, see
Selecting an Algorithm Chooser on page
15. In addition, you must compile and link in
tstdlib.c, which contains the memory
management functions called by the Crypto-C library.
Note: For backward compatibility, the BSAFE 2.x
include file names, global.h and
bsafe2.h, are still valid. If your source code contains the older names, you
should not have any problems.
Step 1: Creating an Algorithm Object
Whatever operation Crypto-C performs, it does so from an algorithm object. An
algorithm object is used to hold information about an algorithm’s parameters and to
keep a context during a cryptographic operation such as encryption or decryption.
For our example, we will build an algorithm object that performs encryption.
You build an algorithm object in Steps 1 to 3. As you go through these steps, you
#include “bsafe.h”