1D2I_PRIVATEKEY(3ossl)               OpenSSL              D2I_PRIVATEKEY(3ossl)
2
3
4

NAME

6       d2i_PrivateKey_ex, d2i_PrivateKey, d2i_PublicKey, d2i_KeyParams,
7       d2i_AutoPrivateKey_ex,  d2i_AutoPrivateKey, i2d_PrivateKey,
8       i2d_PublicKey, i2d_KeyParams, i2d_KeyParams_bio, d2i_PrivateKey_ex_bio,
9       d2i_PrivateKey_bio, d2i_PrivateKey_ex_fp, d2i_PrivateKey_fp,
10       d2i_KeyParams_bio, i2d_PrivateKey_bio, i2d_PrivateKey_fp - decode and
11       encode functions for reading and saving EVP_PKEY structures
12

SYNOPSIS

14        #include <openssl/evp.h>
15
16        EVP_PKEY *d2i_PrivateKey_ex(int type, EVP_PKEY **a, const unsigned char **pp,
17                                    long length, OSSL_LIB_CTX *libctx,
18                                    const char *propq);
19        EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp,
20                                 long length);
21        EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp,
22                                long length);
23        EVP_PKEY *d2i_KeyParams(int type, EVP_PKEY **a, const unsigned char **pp,
24                                long length);
25        EVP_PKEY *d2i_AutoPrivateKey_ex(EVP_PKEY **a, const unsigned char **pp,
26                                        long length, OSSL_LIB_CTX *libctx,
27                                        const char *propq);
28        EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp,
29                                     long length);
30
31        int i2d_PrivateKey(const EVP_PKEY *a, unsigned char **pp);
32        int i2d_PublicKey(const EVP_PKEY *a, unsigned char **pp);
33        int i2d_KeyParams(const EVP_PKEY *a, unsigned char **pp);
34        int i2d_KeyParams_bio(BIO *bp, const EVP_PKEY *pkey);
35        EVP_PKEY *d2i_KeyParams_bio(int type, EVP_PKEY **a, BIO *in);
36
37
38        #include <openssl/x509.h>
39
40        EVP_PKEY *d2i_PrivateKey_ex_bio(BIO *bp, EVP_PKEY **a, OSSL_LIB_CTX *libctx,
41                                        const char *propq);
42        EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a);
43        EVP_PKEY *d2i_PrivateKey_ex_fp(FILE *fp, EVP_PKEY **a, OSSL_LIB_CTX *libctx,
44                                       const char *propq);
45        EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a);
46
47        int i2d_PrivateKey_bio(BIO *bp, const EVP_PKEY *pkey);
48        int i2d_PrivateKey_fp(FILE *fp, const EVP_PKEY *pkey);
49

DESCRIPTION

51       d2i_PrivateKey_ex() decodes a private key using algorithm type. It
52       attempts to use any key-specific format or PKCS#8 unencrypted
53       PrivateKeyInfo format.  The type parameter should be a public key
54       algorithm constant such as EVP_PKEY_RSA. An error occurs if the decoded
55       key does not match type. Some private key decoding implementations may
56       use cryptographic algorithms (for example to automatically derive the
57       public key if it is not explicitly included in the encoding). In this
58       case the supplied library context libctx and property query string
59       propq are used.  If successful and the a parameter is not NULL the
60       function assigns the returned EVP_PKEY structure pointer to *a,
61       overwriting any previous value.
62
63       d2i_PrivateKey() does the same as d2i_PrivateKey_ex() except that the
64       default library context and property query string are used.
65       d2i_PublicKey() does the same for public keys.  d2i_KeyParams() does
66       the same for key parameters.
67
68       The d2i_PrivateKey_ex_bio() and d2i_PrivateKey_bio() functions are
69       similar to d2i_PrivateKey_ex() and d2i_PrivateKey() respectively except
70       that they decode the data read from the given BIO. The
71       d2i_PrivateKey_ex_fp() and d2i_PrivateKey_fp() functions are the same
72       except that they read the data from the given FILE.
73
74       d2i_AutoPrivateKey_ex() and d2i_AutoPrivateKey() are similar to
75       d2i_PrivateKey_ex() and d2i_PrivateKey() respectively except that they
76       attempt to automatically detect the private key format.
77
78       i2d_PrivateKey() encodes a. It uses a key specific format or, if none
79       is defined for that key type, PKCS#8 unencrypted PrivateKeyInfo format.
80       i2d_PublicKey() does the same for public keys.  i2d_KeyParams() does
81       the same for key parameters.  These functions are similar to the
82       d2i_X509() functions; see d2i_X509(3).  i2d_PrivateKey_bio() and
83       i2d_PrivateKey_fp() do the same thing except that they encode to a BIO
84       or FILE respectively. Again, these work similarly to the functions
85       described in d2i_X509(3).
86

NOTES

88       All the functions that operate on data in memory update the data
89       pointer *pp after a successful operation, just like the other d2i and
90       i2d functions; see d2i_X509(3).
91
92       All these functions use DER format and unencrypted keys. Applications
93       wishing to encrypt or decrypt private keys should use other functions
94       such as d2i_PKCS8PrivateKey() instead.
95
96       To decode a key with type EVP_PKEY_EC, d2i_PublicKey() requires *a to
97       be a non-NULL EVP_PKEY structure assigned an EC_KEY structure
98       referencing the proper EC_GROUP.
99

RETURN VALUES

101       The d2i_PrivateKey_ex(), d2i_PrivateKey(), d2i_AutoPrivateKey_ex(),
102       d2i_AutoPrivateKey(), d2i_PrivateKey_ex_bio(), d2i_PrivateKey_bio(),
103       d2i_PrivateKey_ex_fp(), d2i_PrivateKey_fp(), d2i_PublicKey(),
104       d2i_KeyParams() and d2i_KeyParams_bio() functions return a valid
105       EVP_PKEY structure or NULL if an error occurs. The error code can be
106       obtained by calling ERR_get_error(3).
107
108       i2d_PrivateKey(), i2d_PrivateKey_bio(), i2d_PrivateKey_fp(),
109       i2d_PublicKey(), i2d_KeyParams() i2d_KeyParams_bio() return the number
110       of bytes successfully encoded or a negative value if an error occurs.
111       The error code can be obtained by calling ERR_get_error(3).
112

SEE ALSO

114       crypto(7), d2i_PKCS8PrivateKey_bio(3)
115

HISTORY

117       d2i_PrivateKey_ex(), d2i_PrivateKey_ex_bio(), d2i_PrivateKey_ex_fp(),
118       and d2i_AutoPrivateKey_ex() were added in OpenSSL 3.0.
119
121       Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
122
123       Licensed under the Apache License 2.0 (the "License").  You may not use
124       this file except in compliance with the License.  You can obtain a copy
125       in the file LICENSE in the source distribution or at
126       <https://www.openssl.org/source/license.html>.
127
128
129
1303.0.5                             2022-07-05             D2I_PRIVATEKEY(3ossl)
Impressum