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

NAME

6       EVP_PKEY_decrypt_init, EVP_PKEY_decrypt_init_ex, EVP_PKEY_decrypt -
7       decrypt using a public key algorithm
8

SYNOPSIS

10        #include <openssl/evp.h>
11
12        int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx);
13        int EVP_PKEY_decrypt_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]);
14        int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx,
15                             unsigned char *out, size_t *outlen,
16                             const unsigned char *in, size_t inlen);
17

DESCRIPTION

19       The EVP_PKEY_decrypt_init() function initializes a public key algorithm
20       context using key pkey for a decryption operation.
21
22       The EVP_PKEY_decrypt_init_ex() function initializes a public key
23       algorithm context using key pkey for a decryption operation and sets
24       the algorithm specific params.
25
26       The EVP_PKEY_decrypt() function performs a public key decryption
27       operation using ctx. The data to be decrypted is specified using the in
28       and inlen parameters. If out is NULL then the maximum size of the
29       output buffer is written to the outlen parameter. If out is not NULL
30       then before the call the outlen parameter should contain the length of
31       the out buffer, if the call is successful the decrypted data is written
32       to out and the amount of data written to outlen.
33

NOTES

35       After the call to EVP_PKEY_decrypt_init() algorithm specific control
36       operations can be performed to set any appropriate parameters for the
37       operation.  These operations can be included in the
38       EVP_PKEY_decrypt_init_ex() call.
39
40       The function EVP_PKEY_decrypt() can be called more than once on the
41       same context if several operations are performed using the same
42       parameters.
43

RETURN VALUES

45       EVP_PKEY_decrypt_init(), EVP_PKEY_decrypt_init_ex() and
46       EVP_PKEY_decrypt() return 1 for success and 0 or a negative value for
47       failure. In particular a return value of -2 indicates the operation is
48       not supported by the public key algorithm.
49

EXAMPLES

51       Decrypt data using OAEP (for RSA keys):
52
53        #include <openssl/evp.h>
54        #include <openssl/rsa.h>
55
56        EVP_PKEY_CTX *ctx;
57        ENGINE *eng;
58        unsigned char *out, *in;
59        size_t outlen, inlen;
60        EVP_PKEY *key;
61
62        /*
63         * NB: assumes key, eng, in, inlen are already set up
64         * and that key is an RSA private key
65         */
66        ctx = EVP_PKEY_CTX_new(key, eng);
67        if (!ctx)
68            /* Error occurred */
69        if (EVP_PKEY_decrypt_init(ctx) <= 0)
70            /* Error */
71        if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING) <= 0)
72            /* Error */
73
74        /* Determine buffer length */
75        if (EVP_PKEY_decrypt(ctx, NULL, &outlen, in, inlen) <= 0)
76            /* Error */
77
78        out = OPENSSL_malloc(outlen);
79
80        if (!out)
81            /* malloc failure */
82
83        if (EVP_PKEY_decrypt(ctx, out, &outlen, in, inlen) <= 0)
84            /* Error */
85
86        /* Decrypted data is outlen bytes written to buffer out */
87

SEE ALSO

89       EVP_PKEY_CTX_new(3), EVP_PKEY_encrypt(3), EVP_PKEY_sign(3),
90       EVP_PKEY_verify(3), EVP_PKEY_verify_recover(3), EVP_PKEY_derive(3)
91

HISTORY

93       These functions were added in OpenSSL 1.0.0.
94
96       Copyright 2006-2022 The OpenSSL Project Authors. All Rights Reserved.
97
98       Licensed under the Apache License 2.0 (the "License").  You may not use
99       this file except in compliance with the License.  You can obtain a copy
100       in the file LICENSE in the source distribution or at
101       <https://www.openssl.org/source/license.html>.
102
103
104
1053.0.5                             2022-11-01           EVP_PKEY_DECRYPT(3ossl)
Impressum