AsymmetricAlgorithm.ExportEncryptedPkcs8PrivateKeyPem Method

Definition

Overloads

ExportEncryptedPkcs8PrivateKeyPem(ReadOnlySpan<Char>, PbeParameters)

Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a char-based password, PEM encoded.

ExportEncryptedPkcs8PrivateKeyPem(ReadOnlySpan<Byte>, PbeParameters)

Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a byte-based password, PEM encoded.

ExportEncryptedPkcs8PrivateKeyPem(ReadOnlySpan<Char>, PbeParameters)

Source:
AsymmetricAlgorithm.cs
Source:
AsymmetricAlgorithm.cs
Source:
AsymmetricAlgorithm.cs

Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a char-based password, PEM encoded.

C#
public string ExportEncryptedPkcs8PrivateKeyPem(ReadOnlySpan<char> password, System.Security.Cryptography.PbeParameters pbeParameters);

Parameters

password
ReadOnlySpan<Char>

The password to use when encrypting the key material.

pbeParameters
PbeParameters

The password-based encryption (PBE) parameters to use when encrypting the key material.

Returns

A string containing the PEM-encoded PKCS#8 EncryptedPrivateKeyInfo.

Exceptions

The key could not be exported.

Remarks

When pbeParameters indicates an algorithm that uses PBKDF2 (Password-Based Key Derivation Function 2), the password is converted to bytes via the UTF-8 encoding.

          A PEM-encoded PKCS#8 EncryptedPrivateKeyInfo will begin with
         `-----BEGIN ENCRYPTED PRIVATE KEY-----` and end with
         `-----END ENCRYPTED PRIVATE KEY-----`, with the base64 encoded DER
          contents of the key between the PEM boundaries.

          The PEM is encoded according to the IETF RFC 7468 "strict" encoding rules.

Applies to

.NET 10 and other versions
Product Versions
.NET 7, 8, 9, 10

ExportEncryptedPkcs8PrivateKeyPem(ReadOnlySpan<Byte>, PbeParameters)

Source:
AsymmetricAlgorithm.cs
Source:
AsymmetricAlgorithm.cs

Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a byte-based password, PEM encoded.

C#
public string ExportEncryptedPkcs8PrivateKeyPem(ReadOnlySpan<byte> passwordBytes, System.Security.Cryptography.PbeParameters pbeParameters);

Parameters

passwordBytes
ReadOnlySpan<Byte>

The bytes to use as a password when encrypting the key material.

pbeParameters
PbeParameters

The password-based encryption (PBE) parameters to use when encrypting the key material.

Returns

A string containing the PEM-encoded PKCS#8 EncryptedPrivateKeyInfo.

Exceptions

The key could not be exported.

Remarks

A PEM-encoded PKCS#8 EncryptedPrivateKeyInfo will begin with -----BEGIN ENCRYPTED PRIVATE KEY----- and end with -----END ENCRYPTED PRIVATE KEY-----, with the base64 encoded DER contents of the key between the PEM boundaries.

The PEM is encoded according to the IETF RFC 7468 "strict" encoding rules.

Applies to

.NET 10 and other versions
Product Versions
.NET 8, 9, 10