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.

See Also<br />

• NIST web site: http://www.nist.gov/<br />

• Recipes 7.4, 7.11, 8.18<br />

7.16 Representing Public Keys and Certificates<br />

in Binary (DER Encoding)<br />

<strong>Problem</strong><br />

You want to represent a digital certificate or some other cryptographic primitive in a<br />

standard binary format, either for signing or for storing to disk.<br />

Solution<br />

There is an industry-standard way to represent cryptographic objects in binary, but it<br />

isn’t very pretty at all. (You need to use this standard if you want to programmatically<br />

sign an X.509 certificate in a portable way.) We strongly recommend sticking to<br />

standard APIs for encoding and decoding instead of writing your own encoding and<br />

decoding routines.<br />

When storing data on disk, you may want to use a password to encrypt the DERencoded<br />

representation, as discussed in Recipe 4.10.<br />

Discussion<br />

ASN.1 is a language for specifying the fields a data object must contain. It’s similar in<br />

purpose to XML(which it predates). Cryptographers use ASN.1 extensively for<br />

defining precise descriptions of data. For example, the definition of X.509 certificates<br />

is specified in the language. If you look at that specification, you can clearly see<br />

which parts of the certificate are optional and which are required, and see important<br />

properties of all of the fields.<br />

ASN.1 is supposed to be a high-level specification of data. By that, we mean that<br />

there could be a large number of ways to translate ASN.1 data objects into a binary<br />

representation. That is, data may be represented however you want it to be internal<br />

to your applications, but if you want to exchange data in a standard way, you need<br />

to be able to go back and forth from your internal representation to some sort of<br />

standard representation. An ASN.1 representation can be encoded in many ways,<br />

though!<br />

The cryptographic community uses distinguished encoding rules (DER) to specify<br />

how to map an ASN.1 specification of a data object to a binary representation. That<br />

is, if you look at the ASN.1 specification of an X.509 certificate, and you have all the<br />

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