[#EVP_PKEY_encrypt_old]
= EVP&lowbar;PKEY&lowbar;encrypt&lowbar;old
:mrdocs:

Encrypt a session key with a public key using the legacy EVP&lowbar;PKEY path (deprecated)&period;

== Synopsis

Declared in `&lt;openssl&sol;evp&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
&lsqb;&lsqb;deprecated&rsqb;&rsqb;
int
EVP&lowbar;PKEY&lowbar;encrypt&lowbar;old(
    unsigned char* enc&lowbar;key,
    unsigned char const* key,
    int key&lowbar;len,
    xref:EVP_PKEY.adoc[EVP&lowbar;PKEY]* pub&lowbar;key);
----

[WARNING]
====
https://en.cppreference.com/cpp/language/attributes/deprecated[Deprecated^]. Use of this entity is allowed but discouraged.
====
== Description

Prefer EVP&lowbar;PKEY&lowbar;encrypt&lowbar;init() &sol; EVP&lowbar;PKEY&lowbar;encrypt()&period;

== Return Value

Number of encrypted bytes written to `enc&lowbar;key,` or a negative value on error&period;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *enc&lowbar;key*
| Output buffer for the encrypted key material&period;
| *key*
| Plaintext key bytes to encrypt&period;
| *key&lowbar;len*
| Length of `key` in bytes&period;
| *pub&lowbar;key*
| Public key used for encryption (typically RSA)&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
