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

# libressl-d2i\_RSAPublicKey(3)

decode and encode RSA keys and parameters

## NAME

**d2i\_RSAPublicKey**, **i2d\_RSAPublicKey**, **d2i\_RSAPrivateKey**, **i2d\_RSAPrivateKey**, **d2i\_Netscape\_RSA**, **i2d\_Netscape\_RSA**, **d2i\_RSA\_PSS\_PARAMS**, **i2d\_RSA\_PSS\_PARAMS**, **d2i\_RSAPublicKey\_bio**, **d2i\_RSAPublicKey\_fp**, **i2d\_RSAPublicKey\_bio**, **i2d\_RSAPublicKey\_fp**, **d2i\_RSAPrivateKey\_bio**, **d2i\_RSAPrivateKey\_fp**, **i2d\_RSAPrivateKey\_bio**, **i2d\_RSAPrivateKey\_fp**, **d2i\_RSA\_PUBKEY**, **i2d\_RSA\_PUBKEY**, **d2i\_RSA\_PUBKEY\_bio**, **d2i\_RSA\_PUBKEY\_fp**, **i2d\_RSA\_PUBKEY\_bio**, **i2d\_RSA\_PUBKEY\_fp** – decode and encode RSA keys and parameters

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

*RSA* *\**\

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

*int*\

**i2d\_RSAPublicKey**(*RSA \*val\_in*, *unsigned char \*\*der\_out*);

*RSA* *\**\

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

*int*\

**i2d\_RSAPrivateKey**(*RSA \*val\_in*, *unsigned char \*\*der\_out*);

*RSA* *\**\

**d2i\_Netscape\_RSA**(*RSA \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*, *int (\*cb)()*);

*int*\

**i2d\_Netscape\_RSA**(*RSA \*val\_in*, *unsigned char \*\*der\_out*, *int (\*cb)()*);

*RSA\_PSS\_PARAMS* *\**\

**d2i\_RSA\_PSS\_PARAMS**(*RSA\_PSS\_PARAMS \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_RSA\_PSS\_PARAMS**(*RSA\_PSS\_PARAMS \*val\_in*, *unsigned char \*\*der\_out*);

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

*RSA* *\**\

**d2i\_RSAPublicKey\_bio**(*BIO \*in\_bio*, *RSA \*\*val\_out*);

*RSA* *\**\

**d2i\_RSAPublicKey\_fp**(*FILE \*in\_fp*, *RSA \*\*val\_out*);

*int*\

**i2d\_RSAPublicKey\_bio**(*BIO \*out\_bio*, *RSA \*val\_in*);

*int*\

**i2d\_RSAPublicKey\_fp**(*FILE \*out\_fp*, *RSA \*val\_in*);

*RSA* *\**\

**d2i\_RSAPrivateKey\_bio**(*BIO \*in\_bio*, *RSA \*\*val\_out*);

*RSA* *\**\

**d2i\_RSAPrivateKey\_fp**(*FILE \*in\_fp*, *RSA \*\*val\_out*);

*int*\

**i2d\_RSAPrivateKey\_bio**(*BIO \*out\_bio*, *RSA \*val\_in*);

*int*\

**i2d\_RSAPrivateKey\_fp**(*FILE \*out\_fp*, *RSA \*val\_in*);

*RSA* *\**\

**d2i\_RSA\_PUBKEY**(*RSA \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_RSA\_PUBKEY**(*RSA \*val\_in*, *unsigned char \*\*der\_out*);

*RSA* *\**\

**d2i\_RSA\_PUBKEY\_bio**(*BIO \*in\_bio*, *RSA \*\*val\_out*);

*RSA* *\**\

**d2i\_RSA\_PUBKEY\_fp**(*FILE \*in\_fp*, *RSA \*\*val\_out*);

*int*\

**i2d\_RSA\_PUBKEY\_bio**(*BIO \*out\_bio*, *RSA \*val\_in*);

*int*\

**i2d\_RSA\_PUBKEY\_fp**(*FILE \*out\_fp*, *RSA \*val\_in*);

## DESCRIPTION

These functions decode and encode RSA private and public keys. For details about the semantics, examples, caveats, and bugs, see ASN1\_item\_d2i(3).

**d2i\_RSAPublicKey**() and **i2d\_RSAPublicKey**() decode and encode a PKCS#1 *RSAPublicKey* structure defined in RFC 8017 appendix A.1.1. **d2i\_RSAPublicKey\_bio**(), **d2i\_RSAPublicKey\_fp**(), **i2d\_RSAPublicKey\_bio**(), and **i2d\_RSAPublicKey\_fp**() are similar except that they decode or encode using a *BIO* or *FILE* pointer.

**d2i\_RSAPrivateKey**() and **i2d\_RSAPrivateKey**() decode and encode a PKCS#1 *RSAPrivateKey* structure defined in RFC 8017 appendix A.1.2. The *RSA* structure passed to the private key encoding functions should have all the PKCS#1 private key components present. The data encoded by the private key functions is unencrypted and therefore offers no private key security. **d2i\_RSAPrivateKey\_bio**(), **d2i\_RSAPrivateKey\_fp**(), **i2d\_RSAPrivateKey\_bio**(), and **i2d\_RSAPrivateKey\_fp**() are similar except that they decode or encode using a *BIO* or *FILE* pointer.

**d2i\_Netscape\_RSA**() and **i2d\_Netscape\_RSA**() decode and encode an RSA private key in NET format. These functions are present to provide compatibility with certain very old software. The NET format has some severe security weaknesses and should be avoided if possible.

**d2i\_RSA\_PSS\_PARAMS**() and **i2d\_RSA\_PSS\_PARAMS**() decode and encode a PKCS#1 *RSASSA-PSS-params* structure defined in RFC 8017 appendix A.2.3 and documented in RSA\_PSS\_PARAMS\_new(3).

**d2i\_RSA\_PUBKEY**() and **i2d\_RSA\_PUBKEY**() decode and encode an RSA public key using an ASN.1 *SubjectPublicKeyInfo* structure defined in RFC 5280 section 4.1 and documented in X509\_PUBKEY\_new(3). **d2i\_RSA\_PUBKEY\_bio**(), **d2i\_RSA\_PUBKEY\_fp**(), **i2d\_RSA\_PUBKEY\_bio**(), and **i2d\_RSA\_PUBKEY\_fp**() are similar except that they decode or encode using a *BIO* or *FILE* pointer.

## RETURN VALUES

**d2i\_RSAPublicKey**(), **d2i\_RSAPublicKey\_bio**(), **d2i\_RSAPublicKey\_fp**(), **d2i\_RSAPrivateKey**(), **d2i\_RSAPrivateKey\_bio**(), **d2i\_RSAPrivateKey\_fp**(), **d2i\_Netscape\_RSA**(), **d2i\_RSA\_PUBKEY**(), **d2i\_RSA\_PUBKEY\_bio**(), and **d2i\_RSA\_PUBKEY\_fp**() return a valid *RSA* object or NULL if an error occurs.

**d2i\_RSA\_PSS\_PARAMS**() returns a valid *RSA\_PSS\_PARAMS* object or NULL if an error occurs.

**i2d\_RSAPublicKey**(), **i2d\_RSAPrivateKey**(), **i2d\_Netscape\_RSA**(), **i2d\_RSA\_PSS\_PARAMS**(), and **i2d\_RSA\_PUBKEY**() return the number of bytes successfully encoded or a negative value if an error occurs.

**i2d\_RSAPublicKey\_bio**(), **i2d\_RSAPublicKey\_fp**(), **i2d\_RSAPrivateKey\_bio**(), **i2d\_RSAPrivateKey\_fp**(), **i2d\_RSA\_PUBKEY\_bio**(), and **i2d\_RSA\_PUBKEY\_fp**() return 1 for success or 0 if an error occurs.

## SEE ALSO

ASN1\_item\_d2i(3), EVP\_PKEY\_set1\_RSA(3), PEM\_write\_RSAPrivateKey(3), RSA\_new(3), RSA\_PSS\_PARAMS\_new(3), X509\_PUBKEY\_new(3)

## STANDARDS

RFC 8017: PKCS #1: RSA Cryptography Specifications

RFC 5280: Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile, section 4.1: Basic Certificate Fields

## HISTORY

**d2i\_RSAPublicKey**(), **i2d\_RSAPublicKey**(), **d2i\_RSAPrivateKey**(), **i2d\_RSAPrivateKey**(), **d2i\_RSAPrivateKey\_fp**(), **i2d\_RSAPrivateKey\_fp**(), **d2i\_Netscape\_RSA**(), and **i2d\_Netscape\_RSA**() first appeared in SSLeay 0.5.1. **d2i\_RSAPrivateKey\_bio**() and **i2d\_RSAPrivateKey\_bio**() first appeared in SSLeay 0.6.0. **d2i\_RSAPublicKey\_bio**(), **d2i\_RSAPublicKey\_fp**(), **i2d\_RSAPublicKey\_bio**(), and **i2d\_RSAPublicKey\_fp**() first appeared in SSLeay 0.8.1. These functions have been available since OpenBSD 2.4.

**d2i\_RSA\_PUBKEY**(), **i2d\_RSA\_PUBKEY**(), **d2i\_RSA\_PUBKEY\_bio**(), **d2i\_RSA\_PUBKEY\_fp**(), **i2d\_RSA\_PUBKEY\_bio**(), and **i2d\_RSA\_PUBKEY\_fp**() first appeared in OpenSSL 0.9.5 and have been available since OpenBSD 2.7.

**d2i\_RSA\_PSS\_PARAMS**() and **i2d\_RSA\_PSS\_PARAMS**() first appeared in OpenSSL 1.0.1 and have been available since OpenBSD 5.3.
