PKCS8_PKEY_SET0(3)
π PKCS8_PKEY_SET0(3)
okay so bestie, this is a page from the Library Functions Manual β yes the whole libcrypto situation β and it's literally all about peeking at and messing with PKCS#8 PrivateKeyInfo objects. private keys!! the main characters!! πβ¨
πΈ NAME πΈ
PKCS8_pkey_set0, PKCS8_pkey_get0, PKCS8_pkey_add1_attr_by_NID, PKCS8_pkey_get0_attrs β these four icons change and inspect PKCS#8 PrivateKeyInfo objects π«Ά
β¨ SYNOPSIS β¨
so first you gotta pull in the library, it's giving <openssl/x509.h> energy π
library βlibcryptoβ #include <openssl/x509.h>
int
PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *keyinfo, ASN1_OBJECT *aobj,
int version, int ptype, void *pval, unsigned char *data, int len);
int
PKCS8_pkey_get0(const ASN1_OBJECT **paobj, const unsigned char **pdata,
int *plen, const X509_ALGOR **palgor,
const PKCS8_PRIV_KEY_INFO *keyinfo);
int
PKCS8_pkey_add1_attr_by_NID(PKCS8_PRIV_KEY_INFO *keyinfo, int nid,
int type, const unsigned char *data, int len);
const STACK_OF(X509_ATTRIBUTE) *
PKCS8_pkey_get0_attrs(const PKCS8_PRIV_KEY_INFO *keyinfo);
π¦ DESCRIPTION π¦
π PKCS8_pkey_set0()
this one initializes the keyinfo object, like setting up the whole vibe check from scratch π«
- the algorithm gets set to
aobj, with the associated parameter typeptypeand parameter valuepval, all viaX509_ALGOR_set0(3)β and yes it replaces any previous info about the algorithm, no hoarding old data π - unless
dataisNULL, the encoded private key is set to thelenbytes starting atdatausingASN1_STRING_set0(3)β and ngl it does not perform any validation, so it's trusting you fr fr π - if
dataisNULL, the key data stays unchanged, untouched, unbothered π - if the
versionargument is greater than or equal to0, it replaces any existing version; otherwise the version remains unchanged π₯ - and if
keyinfocontains any attributes, they remain unchanged too β they're safe, they're slaying, they're staying π«Ά
π§ PKCS8_pkey_get0()
this one retrieves some info from the keyinfo object π internal pointers to the algorithm OID, the AlgorithmIdentifier, and the encoded private key get stored in *paobj, *palgor, and *pdata respectively β¨
NULLpointers can be passed for any of these three arguments if you don't need that respective info β lowkey efficient π- unless
pdataisNULL,*plenis set to the number of bytes in*pdataπ
π PKCS8_pkey_add1_attr_by_NID()
creates a brand new X.501 Attribute object using X509_ATTRIBUTE_create_by_NID(3) and appends it to the attributes of keyinfo β it's giving "and one more for the collection" π
β RETURN VALUES β
PKCS8_pkey_set0()andPKCS8_pkey_add1_attr_by_NID()return1for success or0for failure β classic binary slay πβPKCS8_pkey_get0()always returns1. iconic, unproblematic, never fails πPKCS8_pkey_get0_attrs()returns an internal pointer to the array of attributes associated withkeyinfo, orNULLif no attributes are set π
π₯ SEE ALSO π₯
go read these next bestie, they're all connected iykyk π§
ASN1_STRING_set0(3)EVP_PKCS82PKEY(3)OBJ_nid2obj(3)PKCS8_PRIV_KEY_INFO_new(3)STACK_OF(3)X509_ALGOR_new(3)X509_ATTRIBUTE_create_by_NID(3)X509_ATTRIBUTE_new(3)
π HISTORY π
PKCS8_pkey_set0()andPKCS8_pkey_get0()first appeared in OpenSSL 1.0.0 and have been available since OpenBSD 4.9 πPKCS8_pkey_add1_attr_by_NID()andPKCS8_pkey_get0_attrs()first appeared in OpenSSL 1.1.0 and have been available since OpenBSD 6.4 πΈ
okay that's the whole page, no cap, every detail intact π β¨ this one came from Debian, dated June 8, 2025 β mwah, go forth and handle your PrivateKeyInfo objects like the main character you are π«Άππ
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2021 Ingo Schwarze <schwarze@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms