---
name: "libressl-d2i_PKCS12"
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-d2i_PKCS12"
---

# libressl-d2i\_PKCS12(3)

decode and encode PKCS#12 structures

## NAME

**d2i\_PKCS12**, **i2d\_PKCS12**, **d2i\_PKCS12\_bio**, **i2d\_PKCS12\_bio**, **d2i\_PKCS12\_fp**, **i2d\_PKCS12\_fp**, **d2i\_PKCS12\_MAC\_DATA**, **i2d\_PKCS12\_MAC\_DATA**, **d2i\_PKCS12\_SAFEBAG**, **i2d\_PKCS12\_SAFEBAG**, **d2i\_PKCS12\_BAGS**, **i2d\_PKCS12\_BAGS** – decode and encode PKCS#12 structures

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/pkcs12.h\>**

*PKCS12* *\**\

**d2i\_PKCS12**(*PKCS12 \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_PKCS12**(*PKCS12 \*val\_in*, *unsigned char \*\*der\_out*);

*PKCS12* *\**\

**d2i\_PKCS12\_bio**(*BIO \*in\_bio*, *PKCS12 \*\*val\_out*);

*int*\

**i2d\_PKCS12\_bio**(*BIO \*out\_bio*, *PKCS12 \*val\_in*);

*PKCS12* *\**\

**d2i\_PKCS12\_fp**(*FILE \*in\_fp*, *PKCS12 \*\*val\_out*);

*int*\

**i2d\_PKCS12\_fp**(*FILE \*out\_fp*, *PKCS12 \*val\_in*);

*PKCS12\_MAC\_DATA* *\**\

**d2i\_PKCS12\_MAC\_DATA**(*PKCS12\_MAC\_DATA \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_PKCS12\_MAC\_DATA**(*PKCS12\_MAC\_DATA \*val\_in*, *unsigned char \*\*der\_out*);

*PKCS12\_SAFEBAG* *\**\

**d2i\_PKCS12\_SAFEBAG**(*PKCS12\_SAFEBAG \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_PKCS12\_SAFEBAG**(*PKCS12\_SAFEBAG \*val\_in*, *unsigned char \*\*der\_out*);

*PKCS12\_BAGS* *\**\

**d2i\_PKCS12\_BAGS**(*PKCS12\_BAGS \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_PKCS12\_BAGS**(*PKCS12\_BAGS \*val\_in*, *unsigned char \*\*der\_out*);

## DESCRIPTION

These functions decode and encode PKCS#12 structures. For details about the semantics, examples, caveats, and bugs, see ASN1\_item\_d2i(3).

**d2i\_PKCS12**() and **i2d\_PKCS12**() decode and encode an ASN.1 *PFX* (personal information exchange) structure defined in RFC 7292 section 4. **d2i\_PKCS12\_bio**(), **i2d\_PKCS12\_bio**(), **d2i\_PKCS12\_fp**(), and **i2d\_PKCS12\_fp**() are similar except that they decode or encode using a *BIO* or *FILE* pointer.

**d2i\_PKCS12\_MAC\_DATA**() and **i2d\_PKCS12\_MAC\_DATA**() decode and encode an ASN.1 *MacData* structure defined in RFC 7292 section 4.

**d2i\_PKCS12\_SAFEBAG**() and **i2d\_PKCS12\_SAFEBAG**() decode and encode an ASN.1 *SafeBag* structure defined in RFC 7292 section 4.2.

**d2i\_PKCS12\_BAGS**() and **i2d\_PKCS12\_BAGS**() decode and encode the bagValue field of an ASN.1 *SafeBag* structure.

## RETURN VALUES

**d2i\_PKCS12**(), **d2i\_PKCS12\_bio**(), and **d2i\_PKCS12\_fp**() return a *PKCS12* object or NULL if an error occurs.

**d2i\_PKCS12\_MAC\_DATA**(), **d2i\_PKCS12\_SAFEBAG**(), and **d2i\_PKCS12\_BAGS**() return a *PKCS12\_MAC\_DATA*, *PKCS12\_SAFEBAG*, or *PKCS12\_BAGS* object, respectively, or NULL if an error occurs.

**i2d\_PKCS12**(), **i2d\_PKCS12\_MAC\_DATA**(), **i2d\_PKCS12\_SAFEBAG**(), and **i2d\_PKCS12\_BAGS**() return the number of bytes successfully encoded or a negative value if an error occurs.

**i2d\_PKCS12\_bio**() and **i2d\_PKCS12\_fp**() return 1 for success or 0 if an error occurs.

## SEE ALSO

ASN1\_item\_d2i(3), PKCS12\_create(3), PKCS12\_new(3), PKCS12\_parse(3), PKCS12\_SAFEBAG\_new(3)

## STANDARDS

RFC 7292: PKCS #12: Personal Information Exchange Syntax

## HISTORY

**d2i\_PKCS12**(), **i2d\_PKCS12**(), **d2i\_PKCS12\_bio**(), **i2d\_PKCS12\_bio**(), **d2i\_PKCS12\_fp**(), **i2d\_PKCS12\_fp**(), **d2i\_PKCS12\_MAC\_DATA**(), **i2d\_PKCS12\_MAC\_DATA**(), **d2i\_PKCS12\_SAFEBAG**(), **i2d\_PKCS12\_SAFEBAG**(), **d2i\_PKCS12\_BAGS**(), and **i2d\_PKCS12\_BAGS**() first appeared in OpenSSL 0.9.3 and have been available since OpenBSD 2.6.
