RSA Key Formats
RSA_MakeKeys
creates a new RSA key pair in two files, one for the public key and one for the private key.
The private key is saved in encrypted form, protected by a password supplied by the user, so it
is never saved explicitly to disk in the clear.
X509_MakeCert
like this:
X509_MakeCertSelf function:
In practice, you use your own private key
and the
X509_CertRequest
function
to create a Certificate Signing Request
and then send it along with a fee to someone like Verisign who will issue
a properly-trusted certificate and return it to you.
These functions are explained diagrammatically in this diagram of RSA Key Functions in CryptoSys PKI (updated April 2006 for new functions in version 2.8).
-----BEGIN FOO BAR KEY----- MIIBgjAcBgoqhkiG9w0BDAEDMA4ECKZesfWLQOiDAgID6ASCAWBu7izm8N4V 2puRO/Mdt+Y8ceywxiC0cE57nrbmvaTSvBwTg9b/xyd8YC6QK7lrhC9Njgp/ ... -----END FOO BAR KEY-----These files can be viewed with a text editor and can be easily transmitted as part of an email message.
X.509 public key certificates are usually named .cer or .der. A PEM-format version might be named .pem. An X.509 certificate is essentially a signed copy of the user's public key plus various other identifying information. There is no accepted convention, though, for naming the raw public and private key files: .pub, .pri, .key, .bin and .pem are frequently used (we use .epk in some of our examples for encrypted private keys - but this is solely our own naming convention).
You can recover the public key directly from a single X.509 certificate using the
RSA_GetPublicKeyFromCert
function, or you can read it in from a BER or PEM public key file using
RSA_ReadPublicKey.
In both cases you end up with the public key in "internal" string format.
You read in a private key from a BER or PEM file using either the
RSA_ReadEncPrivateKey
function plus a password, or using the
RSA_ReadPrivateKeyInfo
function if the file is not encrypted.
To read in from an XML file, in all cases, XML data needs to be read into a string and then reconstructed using the
RSA_FromXMLString
function. See Importing an RSA key from known parameters.
Public key certificates can also come in Cryptographic Message Syntax Standard PKCS#7 format
(typically named .p7b or .p7c, but sometimes mischeviously named .cer) or as part of a
PKCS#12 PFX file (typically called .pfx or .p12).
The PKCS#7 files might contain several certificates in a chain.
Use the
X509_GetCertFromP7Chain
and
X509_GetCertFromPFX
functions to extract a single X.509 certificate from P7c and PFX files respectively.
Encrypted private keys can also come in PFX format: use the
RSA_GetPrivateKeyFromPFX
function to extract a PKCS#8 encrypted private key file.
BEGIN RSA PUBLIC KEY)BEGIN PUBLIC KEY)<RSAKeyValue>BEGIN ENCRYPTED PRIVATE KEY)BEGIN RSA PRIVATE KEY)BEGIN PRIVATE KEY)<RSAKeyPair> and <RSAKeyValue>This page last updated: 13 May 2006
Home |
PKI Home |
Purchase |
Cryptography Software Code |
Contact us
Copyright © 2005-6 D.I. Management Services Pty Limited ABN 78 083 210 584,
Sydney, Australia. All rights reserved.
<www.di-mgt.com.au>
<www.cryptosys.net>