---
name: "libressl-PKCS8_pkey_set0"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-PKCS8_pkey_set0"
---

# libressl-PKCS8\_pkey\_set0(3)

change and inspect PKCS#8 PrivateKeyInfo objects

## NAME

**PKCS8\_pkey\_set0**, **PKCS8\_pkey\_get0**, **PKCS8\_pkey\_add1\_attr\_by\_NID**, **PKCS8\_pkey\_get0\_attrs** – change and inspect PKCS#8 PrivateKeyInfo objects

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#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**() initializes the *keyinfo* object. The algorithm is set to *aobj* with the associated parameter type *ptype* and parameter value *pval* using X509\_ALGOR\_set0(3), replacing any previous information about the algorithm. Unless *data* is NULL, the encoded private key is set to the *len* bytes starting at *data* using ASN1\_STRING\_set0(3), not performing any validation. If *data* is NULL, the key data remains unchanged. If the *version* argument is greater than or equal to 0, it replaces any existing version; otherwise, the version remains unchanged. If *keyinfo* contains any attributes, they remain unchanged.

**PKCS8\_pkey\_get0**() retrieves some information from the *keyinfo* object. Internal pointers to the algorithm OID, the *AlgorithmIdentifier*, and the encoded private key are stored in \**paobj*, \**palgor*, and \**pdata*, respectively. NULL pointers can be passed for any of these three arguments if the respective information is not needed. Unless *pdata* is NULL, \**plen* is set to the number of bytes in \**pdata*.

**PKCS8\_pkey\_add1\_attr\_by\_NID**() creates a new X.501 Attribute object using X509\_ATTRIBUTE\_create\_by\_NID(3) and appends it to the attributes of *keyinfo*.

## RETURN VALUES

**PKCS8\_pkey\_set0**() and **PKCS8\_pkey\_add1\_attr\_by\_NID**() return 1 for success or 0 for failure.

**PKCS8\_pkey\_get0**() always returns 1.

**PKCS8\_pkey\_get0\_attrs**() returns an internal pointer to the array of attributes associated with *keyinfo* or NULL if no attributes are set.

## SEE ALSO

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**() and **PKCS8\_pkey\_get0**() first appeared in OpenSSL 1.0.0 and have been available since OpenBSD 4.9.

**PKCS8\_pkey\_add1\_attr\_by\_NID**() and **PKCS8\_pkey\_get0\_attrs**() first appeared in OpenSSL 1.1.0 and have been available since OpenBSD 6.4.
