Generating a new Token
From OpenCA Labs WiKi
To generate a new PKI_TOKEN use the function PKI_TOKEN_new() or
the PKI_TOKEN_new_null() as in the following example:
#include <libpki/pki.h>
int main () {
PKI_TOKEN *tk = NULL;
/* Initialize the library */
PKI_init_all();
/* Generates an Empty PKI_TOKEN */
tk = PKI_TOKEN_new_null();
if( tk == NULL ) {
printf("ERROR, can not generate a new PKI_TOKEN!\n");
return(1);
}
}
[edit]
Loading an Existing Token
The PKI_TOKEN_new() function allows the developer to load the PKI_TOKEN from an existing Token Configuration file. The configuration files are automatically searched for by the library. Besides the default configuration search paths (Default_Config_Search_Dirs), the developer can specify an additional directory as first parameter (if needed).
The following example will load a PKI_TOKEN named "test".
#include <libpki/pki.h>
int main () {
PKI_TOKEN *tk = NULL;
/* Initialize the library */
PKI_init_all();
/* Loads a PKI_TOKEN */
tk = PKI_TOKEN_new("/my/additional/search/path", "test");
if( tk == NULL ) {
printf("ERROR, can not open the TOKEN!\n");
return(1);
}
}

