21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ing in data, pass in a pointer to a pointer to the encoded object. As with the DER<br />

functions described in Recipe 7.16, OpenSSL increments this pointer.<br />

All of the PEM functions are highly regular. All the input functions and all the output<br />

functions take the same arguments and have the same signature, except that the<br />

second argument changes type based on the type of data object with which you’re<br />

working. For example, the second argument to PEM_write_RSAPrivateKey( ) will be<br />

an RSA object pointer, whereas the second argument to PEM_writeDSAPrivateKey( )<br />

will be a DSA object pointer.<br />

We’ll show you the API by demonstrating how to operate on RSA private keys. Then<br />

we’ll provide a table that gives you the relevant functions for other data types.<br />

Here’s the signature for PEM_write_RSAPrivateKey( ):<br />

int PEM_write_RSAPrivateKey(FILE *fp, RSA *obj, EVP_CIPHER *enc,<br />

unsigned char *kstr, int klen,<br />

pem_password_cb callback, void *cb_arg);<br />

This function has the following arguments:<br />

fp<br />

Pointer to the open file for output.<br />

obj<br />

RSA object that is to be PEM-encoded.<br />

enc<br />

Optional argument that, if not specified as NULL, is the EVP_CIPHER object for the<br />

symmetric encryption algorithm (see Recipe 5.17 for a list of possibilities) that<br />

will be used to encrypt the data before it is base64-encoded. It is a bad idea to<br />

use anything other than a CBC-based cipher.<br />

kstr<br />

Buffer containing the key to be used to encrypt the data. If the data is not<br />

encrypted, this argument should be specified as NULL. Even if the data is to be<br />

encrypted, this buffer may be specified as NULL, in which case the key to use will<br />

be derived from a password or passphrase.<br />

klen<br />

If the key buffer is not specified as NULL, this specifies the length of the buffer in<br />

bytes. If the key buffer is specified as NULL, this should be specified as 0.<br />

callback<br />

If the data is to be encrypted and the key buffer is specified as NULL, this specifies<br />

a pointer to a function that will be called to obtain the password or passphrase<br />

used to derive the encryption key. It may be specified as NULL, in which case<br />

OpenSSL will query the user for the password or passphrase to use.<br />

Representing Keys and Certificates in Plaintext (PEM Encoding) | 359<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!