AsymmetricAlgorithm.TryExportEncryptedPkcs8PrivateKeyPem Method

Definition

Overloads

TryExportEncryptedPkcs8PrivateKeyPem(ReadOnlySpan<Byte>, PbeParameters, Span<Char>, Int32)

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

TryExportEncryptedPkcs8PrivateKeyPem(ReadOnlySpan<Char>, PbeParameters, Span<Char>, Int32)

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

TryExportEncryptedPkcs8PrivateKeyPem(ReadOnlySpan<Byte>, PbeParameters, Span<Char>, Int32)

Source:
AsymmetricAlgorithm.cs
Source:
AsymmetricAlgorithm.cs

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

C#
public bool TryExportEncryptedPkcs8PrivateKeyPem(ReadOnlySpan<byte> passwordBytes, System.Security.Cryptography.PbeParameters pbeParameters, Span<char> destination, out int charsWritten);

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.

destination
Span<Char>

The character span to receive the PEM-encoded PKCS#8 EncryptedPrivateKeyInfo data.

charsWritten
Int32

When this method returns, contains a value that indicates the number of characters written to destination. This parameter is treated as uninitialized.

Returns

true if destination is big enough to receive the output; otherwise, false.

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

TryExportEncryptedPkcs8PrivateKeyPem(ReadOnlySpan<Char>, PbeParameters, Span<Char>, Int32)

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 bool TryExportEncryptedPkcs8PrivateKeyPem(ReadOnlySpan<char> password, System.Security.Cryptography.PbeParameters pbeParameters, Span<char> destination, out int charsWritten);

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.

destination
Span<Char>

The character span to receive the PEM-encoded PKCS#8 EncryptedPrivateKeyInfo data.

charsWritten
Int32

When this method returns, contains a value that indicates the number of characters written to destination. This parameter is treated as uninitialized.

Returns

true if destination is big enough to receive the output; otherwise, false.

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