[#PEM_write_PrivateKey_ex]
= PEM&lowbar;write&lowbar;PrivateKey&lowbar;ex
:mrdocs:

Write a private key to a FILE as PEM with an explicit library context&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
int
PEM&lowbar;write&lowbar;PrivateKey&lowbar;ex(
    FILE* fp,
    xref:EVP_PKEY.adoc[EVP&lowbar;PKEY] const* x,
    xref:EVP_CIPHER-07.adoc[EVP&lowbar;CIPHER] const* enc,
    unsigned char const* kstr,
    int klen,
    xref:pem_password_cb.adoc[pem&lowbar;password&lowbar;cb]* cb,
    void* u,
    xref:OSSL_LIB_CTX.adoc[OSSL&lowbar;LIB&lowbar;CTX]* libctx,
    char const* propq);
----

== Return Value

1 on success, or 0 on failure&period;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *fp*
| FILE to write to&period;
| *x*
| Private key to encode&period;
| *enc*
| Cipher for PKCS&num;8 encryption, or NULL for unencrypted PrivateKeyInfo&period;
| *kstr*
| Optional passphrase bytes&semi; if NULL and `enc` is set, `cb` is used&period;
| *klen*
| Length of `kstr` when provided&period;
| *cb*
| Password callback when a passphrase is needed, or NULL&period;
| *u*
| Application data passed to `cb&period;`
| *libctx*
| Library context used for provider&hyphen;backed encoding, or NULL for the default&period;
| *propq*
| Property query for algorithm fetches, or NULL&period;
|===


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