1306191Sjkim=pod
2306191Sjkim
3306191Sjkim=head1 NAME
4306191Sjkim
5306191Sjkimd2i_Private_key, d2i_AutoPrivateKey, i2d_PrivateKey - decode and encode
6306191Sjkimfunctions for reading and saving EVP_PKEY structures.
7306191Sjkim
8306191Sjkim=head1 SYNOPSIS
9306191Sjkim
10306191Sjkim #include <openssl/evp.h>
11306191Sjkim
12306191Sjkim EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp,
13306191Sjkim                          long length);
14306191Sjkim EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp,
15306191Sjkim                              long length);
16306191Sjkim int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp);
17306191Sjkim
18306191Sjkim=head1 DESCRIPTION
19306191Sjkim
20306191Sjkimd2i_PrivateKey() decodes a private key using algorithm B<type>. It attempts to
21306191Sjkimuse any key specific format or PKCS#8 unencrypted PrivateKeyInfo format. The
22306191SjkimB<type> parameter should be a public key algorithm constant such as
23306191SjkimB<EVP_PKEY_RSA>. An error occurs if the decoded key does not match B<type>.
24306191Sjkim
25306191Sjkimd2i_AutoPrivateKey() is similar to d2i_PrivateKey() except it attempts to
26306191Sjkimautomatically detect the private key format.
27306191Sjkim
28306191Sjkimi2d_PrivateKey() encodes B<key>. It uses a key specific format or, if none is
29306191Sjkimdefined for that key type, PKCS#8 unencrypted PrivateKeyInfo format.
30306191Sjkim
31306191SjkimThese functions are similar to the d2i_X509() functions, and you should refer to
32306191Sjkimthat page for a detailed description (see L<d2i_X509(3)>).
33306191Sjkim
34306191Sjkim=head1 NOTES
35306191Sjkim
36306191SjkimAll these functions use DER format and unencrypted keys. Applications wishing
37306191Sjkimto encrypt or decrypt private keys should use other functions such as
38306191Sjkimd2i_PKC8PrivateKey() instead.
39306191Sjkim
40306191SjkimIf the B<*a> is not NULL when calling d2i_PrivateKey() or d2i_AutoPrivateKey()
41306191Sjkim(i.e. an existing structure is being reused) and the key format is PKCS#8
42306191Sjkimthen B<*a> will be freed and replaced on a successful call.
43306191Sjkim
44306191Sjkim=head1 RETURN VALUES
45306191Sjkim
46306191Sjkimd2i_PrivateKey() and d2i_AutoPrivateKey() return a valid B<EVP_KEY> structure
47306191Sjkimor B<NULL> if an error occurs. The error code can be obtained by calling
48306191SjkimL<ERR_get_error(3)>.
49306191Sjkim
50306191Sjkimi2d_PrivateKey() returns the number of bytes successfully encoded or a
51306191Sjkimnegative value if an error occurs. The error code can be obtained by calling
52306191SjkimL<ERR_get_error(3)>.
53306191Sjkim
54306191Sjkim=head1 SEE ALSO
55306191Sjkim
56306191SjkimL<crypto(3)>,
57306191SjkimL<d2i_PKCS8PrivateKey(3)>
58306191Sjkim
59306191Sjkim=cut
60