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

# libressl-d2i\_PKCS7(3)

decode and encode PKCS#7 data structures

## NAME

**d2i\_PKCS7**, **i2d\_PKCS7**, **d2i\_PKCS7\_bio**, **i2d\_PKCS7\_bio**, **d2i\_PKCS7\_fp**, **i2d\_PKCS7\_fp**, **d2i\_PKCS7\_DIGEST**, **i2d\_PKCS7\_DIGEST**, **d2i\_PKCS7\_ENCRYPT**, **i2d\_PKCS7\_ENCRYPT**, **d2i\_PKCS7\_ENC\_CONTENT**, **i2d\_PKCS7\_ENC\_CONTENT**, **d2i\_PKCS7\_ENVELOPE**, **i2d\_PKCS7\_ENVELOPE**, **d2i\_PKCS7\_ISSUER\_AND\_SERIAL**, **i2d\_PKCS7\_ISSUER\_AND\_SERIAL**, **d2i\_PKCS7\_RECIP\_INFO**, **i2d\_PKCS7\_RECIP\_INFO**, **d2i\_PKCS7\_SIGNED**, **i2d\_PKCS7\_SIGNED**, **d2i\_PKCS7\_SIGNER\_INFO**, **i2d\_PKCS7\_SIGNER\_INFO**, **d2i\_PKCS7\_SIGN\_ENVELOPE**, **i2d\_PKCS7\_SIGN\_ENVELOPE** – decode and encode PKCS#7 data structures

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

*PKCS7* *\**\

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

*int*\

**i2d\_PKCS7**(*PKCS7 \*val\_in*, *unsigned char \*\*der\_out*);

*PKCS7* *\**\

**d2i\_PKCS7\_bio**(*BIO \*in\_bio*, *PKCS7 \*\*val\_out*);

*int*\

**i2d\_PKCS7\_bio**(*BIO \*out\_bio*, *PKCS7 \*val\_in*);

*PKCS7* *\**\

**d2i\_PKCS7\_fp**(*FILE \*in\_fp*, *PKCS7 \*\*val\_out*);

*int*\

**i2d\_PKCS7\_fp**(*FILE \*out\_fp*, *PKCS7 \*val\_in*);

*PKCS7\_DIGEST* *\**\

**d2i\_PKCS7\_DIGEST**(*PKCS7\_DIGEST \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_PKCS7\_DIGEST**(*PKCS7\_DIGEST \*val\_in*, *unsigned char \*\*der\_out*);

*PKCS7\_ENCRYPT* *\**\

**d2i\_PKCS7\_ENCRYPT**(*PKCS7\_ENCRYPT \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_PKCS7\_ENCRYPT**(*PKCS7\_ENCRYPT \*val\_in*, *unsigned char \*\*der\_out*);

*PKCS7\_ENC\_CONTENT* *\**\

**d2i\_PKCS7\_ENC\_CONTENT**(*PKCS7\_ENC\_CONTENT \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_PKCS7\_ENC\_CONTENT**(*PKCS7\_ENC\_CONTENT \*val\_in*, *unsigned char \*\*der\_out*);

*PKCS7\_ENVELOPE* *\**\

**d2i\_PKCS7\_ENVELOPE**(*PKCS7\_ENVELOPE \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_PKCS7\_ENVELOPE**(*PKCS7\_ENVELOPE \*val\_in*, *unsigned char \*\*der\_out*);

*PKCS7\_ISSUER\_AND\_SERIAL* *\**\

**d2i\_PKCS7\_ISSUER\_AND\_SERIAL**(*PKCS7\_ISSUER\_AND\_SERIAL \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_PKCS7\_ISSUER\_AND\_SERIAL**(*PKCS7\_ISSUER\_AND\_SERIAL \*val\_in*, *unsigned char \*\*der\_out*);

*PKCS7\_RECIP\_INFO* *\**\

**d2i\_PKCS7\_RECIP\_INFO**(*PKCS7\_RECIP\_INFO \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_PKCS7\_RECIP\_INFO**(*PKCS7\_RECIP\_INFO \*val\_in*, *unsigned char \*\*der\_out*);

*PKCS7\_SIGNED* *\**\

**d2i\_PKCS7\_SIGNED**(*PKCS7\_SIGNED \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_PKCS7\_SIGNED**(*PKCS7\_SIGNED \*val\_in*, *unsigned char \*\*der\_out*);

*PKCS7\_SIGNER\_INFO* *\**\

**d2i\_PKCS7\_SIGNER\_INFO**(*PKCS7\_SIGNER\_INFO \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_PKCS7\_SIGNER\_INFO**(*PKCS7\_SIGNER\_INFO \*val\_in*, *unsigned char \*\*der\_out*);

*PKCS7\_SIGN\_ENVELOPE* *\**\

**d2i\_PKCS7\_SIGN\_ENVELOPE**(*PKCS7\_SIGN\_ENVELOPE \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_PKCS7\_SIGN\_ENVELOPE**(*PKCS7\_SIGN\_ENVELOPE \*val\_in*, *unsigned char \*\*der\_out*);

## DESCRIPTION

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

**d2i\_PKCS7**() and **i2d\_PKCS7**() decode and encode an ASN.1 *ContentInfo* structure defined in RFC 2315 section 7. **d2i\_PKCS7\_bio**(), **i2d\_PKCS7\_bio**(), **d2i\_PKCS7\_fp**(), and **i2d\_PKCS7\_fp**() are similar except that they decode or encode using a *BIO* or *FILE* pointer.

**d2i\_PKCS7\_DIGEST**() and **i2d\_PKCS7\_DIGEST**() decode and encode an ASN.1 *DigestedData* structure defined in RFC 2315 section 12.

**d2i\_PKCS7\_ENCRYPT**() and **i2d\_PKCS7\_ENCRYPT**() decode and encode an ASN.1 *EncryptedData* structure defined in RFC 2315 section 13.

**d2i\_PKCS7\_ENC\_CONTENT**() and **i2d\_PKCS7\_ENC\_CONTENT**() decode and encode an ASN.1 *EncryptedContentInfo* structure defined in RFC 2315 section 10.1.

**d2i\_PKCS7\_ENVELOPE**() and **i2d\_PKCS7\_ENVELOPE**() decode and encode an ASN.1 *EnvelopedData* structure defined in RFC 2315 section 10.

**d2i\_PKCS7\_ISSUER\_AND\_SERIAL**() and **i2d\_PKCS7\_ISSUER\_AND\_SERIAL**() decode and encode an ASN.1 *IssuerAndSerialNumber* structure defined in RFC 2315 section 6.7.

**d2i\_PKCS7\_RECIP\_INFO**() and **i2d\_PKCS7\_RECIP\_INFO**() decode and encode an ASN.1 *RecipientInfo* structure defined in RFC 2315 section 10.2.

**d2i\_PKCS7\_SIGNED**() and **i2d\_PKCS7\_SIGNED**() decode and encode an ASN.1 *SignedData* structure defined in RFC 2315 section 9.

**d2i\_PKCS7\_SIGNER\_INFO**() and **i2d\_PKCS7\_SIGNER\_INFO**() decode and encode an ASN.1 *SignerInfo* structure defined in RFC 2315 section 9.2.

**d2i\_PKCS7\_SIGN\_ENVELOPE**() and **i2d\_PKCS7\_SIGN\_ENVELOPE**() decode and encode an ASN.1 *SignedAndEnvelopedData* structure defined in RFC 2315 section 11.

## RETURN VALUES

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

**d2i\_PKCS7\_DIGEST**(), **d2i\_PKCS7\_ENCRYPT**(), **d2i\_PKCS7\_ENC\_CONTENT**(), **d2i\_PKCS7\_ENVELOPE**(), **d2i\_PKCS7\_ISSUER\_AND\_SERIAL**(), **d2i\_PKCS7\_RECIP\_INFO**(), **d2i\_PKCS7\_SIGNED**(), **d2i\_PKCS7\_SIGNER\_INFO**(), and **d2i\_PKCS7\_SIGN\_ENVELOPE**() return an object of the respective type or NULL if an error occurs.

**i2d\_PKCS7**(), **i2d\_PKCS7\_DIGEST**(), **i2d\_PKCS7\_ENCRYPT**(), **i2d\_PKCS7\_ENC\_CONTENT**(), **i2d\_PKCS7\_ENVELOPE**(), **i2d\_PKCS7\_ISSUER\_AND\_SERIAL**(), **i2d\_PKCS7\_RECIP\_INFO**(), **i2d\_PKCS7\_SIGNED**(), **i2d\_PKCS7\_SIGNER\_INFO**(), and **i2d\_PKCS7\_SIGN\_ENVELOPE**() return the number of bytes successfully encoded or a negative value if an error occurs.

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

## SEE ALSO

ASN1\_item\_d2i(3), i2d\_PKCS7\_bio\_stream(3), PEM\_write\_bio\_PKCS7\_stream(3), PEM\_write\_PKCS7(3), PKCS7\_new(3), SMIME\_write\_PKCS7(3)

## STANDARDS

RFC 2315: PKCS #7: Cryptographic Message Syntax Version 1.5

## HISTORY

**d2i\_PKCS7**(), **i2d\_PKCS7**(), **d2i\_PKCS7\_bio**(), **i2d\_PKCS7\_bio**(), **d2i\_PKCS7\_fp**(), **i2d\_PKCS7\_fp**(), **d2i\_PKCS7\_DIGEST**(), **i2d\_PKCS7\_DIGEST**(), **d2i\_PKCS7\_ENCRYPT**(), **i2d\_PKCS7\_ENCRYPT**(), **d2i\_PKCS7\_ENC\_CONTENT**(), **i2d\_PKCS7\_ENC\_CONTENT**(), **d2i\_PKCS7\_ENVELOPE**(), **i2d\_PKCS7\_ENVELOPE**(), **d2i\_PKCS7\_ISSUER\_AND\_SERIAL**(), **i2d\_PKCS7\_ISSUER\_AND\_SERIAL**(), **d2i\_PKCS7\_RECIP\_INFO**(), **i2d\_PKCS7\_RECIP\_INFO**(), **d2i\_PKCS7\_SIGNED**(), **i2d\_PKCS7\_SIGNED**(), **d2i\_PKCS7\_SIGNER\_INFO**(), **i2d\_PKCS7\_SIGNER\_INFO**(), **d2i\_PKCS7\_SIGN\_ENVELOPE**(), and **i2d\_PKCS7\_SIGN\_ENVELOPE**() first appeared in SSLeay 0.5.1 and have been available since OpenBSD 2.4.
