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.

Table 7-5. PEM encryption algorithms supported by OpenSSL<br />

Cipher String<br />

AES with 128-bit keys AES-128-CBC<br />

AES with 192-bit keys AES-192-CBC<br />

AES with 256-bit keys AES-256-CBC<br />

Blowfish BF-CBC<br />

CAST5 CAST-CBC<br />

DES DES-CBC<br />

DESX DESX<br />

2-key Triple-DES DES-EDE-CBC<br />

3-key Triple-DES DES-EDE3-CBC<br />

IDEA IDEA-CBC<br />

RC2 RC2-CBC<br />

RC5 with 128-bit keys and 12 rounds RC5-CBC<br />

The part of the DEK-Info field after the comma is a CBC initialization vector (which<br />

should be randomly generated), represented in uppercase hexadecimal.<br />

The way encrypted PEM representations work in OpenSSL is as follows:<br />

1. The data is DER-encoded.<br />

2. The data is encrypted using a key that isn’t specified anywhere (i.e., it’s not<br />

placed in the headers, for obvious reasons). Usually, the user must type in a<br />

password to derive an encryption key. (See Recipe 4.10. *) The key-from-password<br />

functionality has the initialization vector double as a salt value, which is<br />

probably okay.<br />

3. The encrypted data is base64-encoded.<br />

The OpenSSLAPI for PEM encoding and decoding (include openssl/pem.h) only<br />

allows you to operate on FILE or OpenSSL BIO objects, which are the generic<br />

OpenSSLIO abstraction. If you need to output to memory, you can either use a<br />

memory BIO or get the DER representation and encode it by hand.<br />

The BIO API and the FILE API are similar. The BIO API changes the name of each<br />

function in a predictable way, and the first argument to each function is a pointer to<br />

a BIO object instead of a FILE object. The object type on which you’re operating is<br />

always the second argument to a PEM function when outputting PEM. When read-<br />

* OpenSSLuses PKCS #5 Version 1.5 for key derivation. PKCS #5 is an earlier version of the algorithm<br />

described in Recipe 4.10. MD5 is used as the hash algorithm with an iteration count of 1. There are some<br />

differences between PKCS #5 Version 1.5 and Version 2.0. If you don’t care about OpenSSLcompatibility,<br />

you should definitely use Version 2.0 (the man pages even recommend it).<br />

358 | 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!