แก้ไข

แชร์ผ่าน


X509Certificate2.CreateFromEncryptedPem Method

Definition

Creates a new X509 certificate from the contents of an RFC 7468 PEM-encoded certificate and password protected private key.

public:
 static System::Security::Cryptography::X509Certificates::X509Certificate2 ^ CreateFromEncryptedPem(ReadOnlySpan<char> certPem, ReadOnlySpan<char> keyPem, ReadOnlySpan<char> password);
public static System.Security.Cryptography.X509Certificates.X509Certificate2 CreateFromEncryptedPem (ReadOnlySpan<char> certPem, ReadOnlySpan<char> keyPem, ReadOnlySpan<char> password);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public static System.Security.Cryptography.X509Certificates.X509Certificate2 CreateFromEncryptedPem (ReadOnlySpan<char> certPem, ReadOnlySpan<char> keyPem, ReadOnlySpan<char> password);
static member CreateFromEncryptedPem : ReadOnlySpan<char> * ReadOnlySpan<char> * ReadOnlySpan<char> -> System.Security.Cryptography.X509Certificates.X509Certificate2
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
static member CreateFromEncryptedPem : ReadOnlySpan<char> * ReadOnlySpan<char> * ReadOnlySpan<char> -> System.Security.Cryptography.X509Certificates.X509Certificate2
Public Shared Function CreateFromEncryptedPem (certPem As ReadOnlySpan(Of Char), keyPem As ReadOnlySpan(Of Char), password As ReadOnlySpan(Of Char)) As X509Certificate2

Parameters

certPem
ReadOnlySpan<Char>

The text of the PEM-encoded X509 certificate.

keyPem
ReadOnlySpan<Char>

The text of the password protected PEM-encoded private key.

password
ReadOnlySpan<Char>

The password for the encrypted PEM.

Returns

A new certificate with the private key.

Attributes

Exceptions

The contents of certPem do not contain a PEM-encoded certificate, or it is malformed.

-or-

The contents of keyPem do not contain a password protected PEM-encoded private key, or it is malformed.

-or-

The contents of keyPem contains a key that does not match the public key in the certificate.

-or-

The certificate uses an unknown public key algorithm.

-or-

The password specified for the private key is incorrect.

Remarks

Password protected PEM-encoded keys are always expected to have the PEM label "ENCRYPTED PRIVATE KEY".

PEM-encoded items that have a different label are ignored.

If the PEM-encoded certificate and private key are in the same text, use the same string for both certPem and keyPem, for example, CreateFromEncryptedPem(combinedCertAndKey, combinedCertAndKey, theKeyPassword);. Combined PEM-encoded certificates and keys do not require a specific order. For the certificate, the first certificate with a CERTIFICATE label is loaded. For the private key, the first private key with the label "ENCRYPTED PRIVATE KEY" is loaded. More advanced scenarios for loading certificates and private keys can leverage PemEncoding to enumerate PEM-encoded values and apply any custom loading behavior.

For PEM-encoded keys without a password, use CreateFromPem(ReadOnlySpan<Char>, ReadOnlySpan<Char>).

Applies to