EVP_PKEY_TODATA(3ossl)

✨ EVP_PKEY_TODATA ✨

okay so bestie, welcome to the OpenSSL manual page for EVP_PKEY_todata and EVP_PKEY_export β€” the two functions whose whole job is handing you your key's values as an array of key parameters. it's giving "unpack your bags, we're staying" πŸ’…


🌸 SYNOPSIS 🌸

#include <openssl/evp.h>

int EVP_PKEY_todata(const EVP_PKEY *pkey, int selection, OSSL_PARAM **params);
int EVP_PKEY_export(const EVP_PKEY *pkey, int selection,
                    OSSL_CALLBACK *export_cb, void *export_cbarg);

πŸ’– DESCRIPTION πŸ’–

So the functions we're talking about here are the ones you use to pull the actual values out of an EVP_PKEY key and get them back as an array of OSSL_PARAM(3). like, the key goes in, the little parameter array comes out. iconic behaviour, no notes ✨

  • EVP_PKEY_todata() β€” this one extracts values from a key pkey using the selection. and what even is selection, you ask? it's described over in "Selections" in EVP_PKEY_fromdata(3), go check it out 🫢. and listen, when you're done with the params it gives you, you must use OSSL_PARAM_free(3) to free the returned parameters in *params. don't just leave them lying around, that's not the vibe 😭
  • EVP_PKEY_export() β€” this is basically EVP_PKEY_todata()'s sibling, except instead of handing you a params array directly it uses a callback export_cb, and it passes that callback the value of export_cbarg. see openssl-core.h(7) for more info about how that callback works πŸ¦‹
🚨 okay this part is IMPORTANT bestie: the OSSL_PARAM(3) array that gets passed to the callback is not persistent after the callback returns. like it's gone, it's not sticking around, it said "my work here is done". so if you need any of those items later you have to preserve the items you actually care about yourself, or just use EVP_PKEY_todata() instead if persistence is what you're after. periodt πŸ’€

πŸ“ NOTES πŸ“

These functions only work with key management methods coming from a provider. no provider, no party πŸŽ€

Also, this is the mirror function to EVP_PKEY_fromdata(3). yes, they're mirrors, they're the same picture, one goes in and one comes out, we love a matching set 🌈


πŸ‘‘ RETURN VALUES πŸ‘‘

EVP_PKEY_todata() and EVP_PKEY_export() return 1 for success and 0 for failure. that's it, that's the whole range. 1 = slay, 0 = not slay πŸ’…


πŸ”₯ SEE ALSO πŸ”₯


πŸ¦‹ HISTORY πŸ¦‹

  • These functions were added in OpenSSL 3.0. a classic, a legend, an elder πŸ’œ
  • Support for ML-DSA, ML-KEM and SLH-DSA was added in OpenSSL 3.5. new girls on the block, and they ate πŸ“

Copyright 2021-2025 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


okay that's the whole page bestie, go forth and export those key params responsibly 🫢 this has been the EVP_PKEY_TODATA(3ossl) page from OpenSSL 3.5.9, dated 2026-09-29 β€” mwah, drink water, free your OSSL_PARAMs βœ¨πŸ’–πŸ§š

πŸ“¦ where this page comes from