Chapter 2 Quick Start 13
Introductory Example
See the description and prototype in Chapter 4 of the Reference Manual for
B_EncryptInit:
As in Step 2, the first argument is the algorithm object; once again, we use
rc4Encrypter
. The next three arguments are new.
Step 3a: Creating a Key Object
The second argument is a key object, which is used to hold any key-related
information, such as the RC4 key, and to supply this information to functions that
require it. Before we can pass a key object as an argument, we must create and set it.
Creating a key object is similar to creating an algorithm object. We name our key
object
rc4Key
and declare it as follows:
where B_KEY_OBJ is defined in bsafe.h:
typedef POINTER B_KEY_OBJ;
Chapter 4 of the Reference Manual gives the description and prototype of
B_CreateKeyObject:
For our example, we use:
Step 3b: Setting a Key Object
We have a key object, but it is not yet distinguished as an RC4 key. To distinguish the
int B_EncryptInit (
B_ALGORITHM_OBJ algorithmObject, /* algorithm object */
B_KEY_OBJ keyObject, /* key object */
B_ALGORITHM_CHOOSER algorithmChooser, /* algorithm chooser */
A_SURRENDER_CTX *surrenderContext /* surrender context */
);
B_KEY_OBJ rc4Key = (B_KEY_OBJ)NULL_PTR;
int B_CreateKeyObject (
B_KEY_OBJ *keyObject /* new key object */
);
if ((status = B_CreateKeyObject (&rc4Key)) != 0)
break;