21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

cb_arg<br />

If a callback function is specified to obtain the password or passphrase for key<br />

derivation, this application-specific value is passed directly to the callback function.<br />

If encryption is desired, OpenSSLwill use PKCS #5 Version 1.5 to derive an encryption<br />

key from a password. This is an earlier version of the algorithm described in<br />

Recipe 4.10.<br />

This function will return 1 if the encoding is successful, 0 otherwise (for example, if<br />

the underlying file is not open for writing).<br />

The type pem_password_cb is defined as follows:<br />

typedef int (*pem_password_cb)(char *buf, int len, int rwflag, void *cb_arg);<br />

It has the following arguments:<br />

buf<br />

Buffer into which the password or passphrase is to be written.<br />

len<br />

Length in bytes of the password or passphrase buffer.<br />

rwflag<br />

Indicates whether the password is to be used for encryption or decryption. For<br />

encryption (when writing out data in PEM format), the argument will be 1; otherwise,<br />

it will be 0.<br />

cb_arg<br />

This application-specific value is passed in from the final argument to the PEM<br />

encoding or decoding function that caused this callback to be made.<br />

Make sure that you do not overflow buf when writing data into it!<br />

Your callback function is expected to return 1 if it successfully reads a password;<br />

otherwise, it should return 0.<br />

The function for writing an RSA private key to a BIO object has the following signature,<br />

which is essentially the same as the function for writing an RSA private key to a<br />

FILE object. The only difference is that the first argument is the BIO object to write to<br />

instead of a FILE object.<br />

int PEM_write_bio_RSAPrivateKey(BIO *bio, RSA *obj, EVP_CIPHER *enc,<br />

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

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

360 | Chapter 7: Public Key Cryptography<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!