Lower Level API
From OpenCA Labs WiKi
[edit]
Introduction
This pages are intended to provide support about LibPKI (http://www.openca.org/projects/libpki) usage by simple tutorials and small programs on the lower level of the API. Developers are strongly suggested to use the PKI Token interface in their applications.
[edit]
Generating KEYPAIRS
Here it is a simple example that generates an RSA keypair:
#include <libpki/pki.h>
int main (int argc, char *argv[] ) {
PKI_KEYPAIR *p = NULL;
/* Now Generate an RSA PKI_KEYPAIR */
p = PKI_KEYPAIR_new( PKI_SCHEME_RSA, 4096, NULL, NULL );
/* Let's write the keypair to a file */
if(!PKI_KEYPAIR_write_file( p, PKI_FORMAT_PEM, "keypair.pem" )) {
printf("<file write error>\n");
};
return(0);
}
To generate a keypair using a different scheme (currently supported are RSA, DSA and ECDSA), simply use a different PKI_SCHEME_* parameter in the PKI_KEYPAIR_new(), for example to generate a new ECDSA keypair:
#include <libpki/pki.h>
int main (int argc, char *argv[] ) {
PKI_KEYPAIR *p = NULL;
/* Now Generate an RSA PKI_KEYPAIR */
p = PKI_KEYPAIR_new( PKI_SCHEME_RSA, 4096, NULL, NULL );
/* Let's write the keypair to a file */
if(!PKI_KEYPAIR_write_file( p, PKI_FORMAT_PEM, "keypair.pem" )) {
printf("<file write error>\n");
};
return(0);
}

