[#PEM_write_PrivateKey_ex] = PEM_write_PrivateKey_ex :mrdocs: Write a private key to a FILE as PEM with an explicit library context. == Synopsis Declared in `<openssl/pem.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- int PEM_write_PrivateKey_ex( FILE* fp, xref:EVP_PKEY.adoc[EVP_PKEY] const* x, xref:EVP_CIPHER-07.adoc[EVP_CIPHER] const* enc, unsigned char const* kstr, int klen, xref:pem_password_cb.adoc[pem_password_cb]* cb, void* u, xref:OSSL_LIB_CTX.adoc[OSSL_LIB_CTX]* libctx, char const* propq); ---- == Return Value 1 on success, or 0 on failure. == Parameters [cols="1,4"] |=== | Name| Description | *fp* | FILE to write to. | *x* | Private key to encode. | *enc* | Cipher for PKCS#8 encryption, or NULL for unencrypted PrivateKeyInfo. | *kstr* | Optional passphrase bytes; if NULL and `enc` is set, `cb` is used. | *klen* | Length of `kstr` when provided. | *cb* | Password callback when a passphrase is needed, or NULL. | *u* | Application data passed to `cb.` | *libctx* | Library context used for provider‐backed encoding, or NULL for the default. | *propq* | Property query for algorithm fetches, or NULL. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#