1EVP_PKEY_DECRYPT(3) OpenSSL EVP_PKEY_DECRYPT(3)
2
3
4
6 EVP_PKEY_decrypt_init, EVP_PKEY_decrypt - decrypt using a public key
7 algorithm
8
10 #include <openssl/evp.h>
11
12 int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx);
13 int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx,
14 unsigned char *out, size_t *outlen,
15 const unsigned char *in, size_t inlen);
16
18 The EVP_PKEY_decrypt_init() function initializes a public key algorithm
19 context using key pkey for a decryption operation.
20
21 The EVP_PKEY_decrypt() function performs a public key decryption
22 operation using ctx. The data to be decrypted is specified using the in
23 and inlen parameters. If out is NULL then the maximum size of the
24 output buffer is written to the outlen parameter. If out is not NULL
25 then before the call the outlen parameter should contain the length of
26 the out buffer, if the call is successful the decrypted data is written
27 to out and the amount of data written to outlen.
28
30 After the call to EVP_PKEY_decrypt_init() algorithm specific control
31 operations can be performed to set any appropriate parameters for the
32 operation.
33
34 The function EVP_PKEY_decrypt() can be called more than once on the
35 same context if several operations are performed using the same
36 parameters.
37
39 EVP_PKEY_decrypt_init() and EVP_PKEY_decrypt() return 1 for success and
40 0 or a negative value for failure. In particular a return value of -2
41 indicates the operation is not supported by the public key algorithm.
42
44 Decrypt data using OAEP (for RSA keys):
45
46 #include <openssl/evp.h>
47 #include <openssl/rsa.h>
48
49 EVP_PKEY_CTX *ctx;
50 ENGINE *eng;
51 unsigned char *out, *in;
52 size_t outlen, inlen;
53 EVP_PKEY *key;
54
55 /*
56 * NB: assumes key, eng, in, inlen are already set up
57 * and that key is an RSA private key
58 */
59 ctx = EVP_PKEY_CTX_new(key, eng);
60 if (!ctx)
61 /* Error occurred */
62 if (EVP_PKEY_decrypt_init(ctx) <= 0)
63 /* Error */
64 if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_OAEP_PADDING) <= 0)
65 /* Error */
66
67 /* Determine buffer length */
68 if (EVP_PKEY_decrypt(ctx, NULL, &outlen, in, inlen) <= 0)
69 /* Error */
70
71 out = OPENSSL_malloc(outlen);
72
73 if (!out)
74 /* malloc failure */
75
76 if (EVP_PKEY_decrypt(ctx, out, &outlen, in, inlen) <= 0)
77 /* Error */
78
79 /* Decrypted data is outlen bytes written to buffer out */
80
82 EVP_PKEY_CTX_new(3), EVP_PKEY_encrypt(3), EVP_PKEY_sign(3),
83 EVP_PKEY_verify(3), EVP_PKEY_verify_recover(3), EVP_PKEY_derive(3)
84
86 These functions were added in OpenSSL 1.0.0.
87
89 Copyright 2006-2019 The OpenSSL Project Authors. All Rights Reserved.
90
91 Licensed under the OpenSSL license (the "License"). You may not use
92 this file except in compliance with the License. You can obtain a copy
93 in the file LICENSE in the source distribution or at
94 <https://www.openssl.org/source/license.html>.
95
96
97
981.1.1l 2021-09-15 EVP_PKEY_DECRYPT(3)