AsymmetricAlgorithm.ImportPkcs8PrivateKey Method

Definition

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

When overriden in a derived class, imports the public/private keypair from a PKCS#8 PrivateKeyInfo structure after decryption, replacing the keys for this object.

C#
public virtual void ImportPkcs8PrivateKey(ReadOnlySpan<byte> source, out int bytesRead);

Parameters

source
ReadOnlySpan<Byte>

The bytes of a PKCS#8 PrivateKeyInfo structure in the ASN.1-BER encoding.

bytesRead
Int32

When this method returns, contains a value that indicates the number of bytes read from source. This parameter is treated as uninitialized.

Exceptions

The contents of source do not represent an ASN.1-BER-encoded PKCS#8 PrivateKeyInfo structure.

-or-

The contents of source indicate the key is for an algorithm other than the algorithm represented by this instance.

-or-

The contents of source represent the key in a format that is not supported.

-or-

The algorithm-specific key import failed.

A derived type has not overriden this member.

Remarks

This method only supports the binary (BER/CER/DER) encoding of PrivateKeyInfo. If the value is Base64-encoded or in the PEM text format, the caller must Base64-decode the contents before calling this method.

Because algorithm-specific support is required to interpret the contents of this data format, ImportPkcs8PrivateKey throws a NotImplementedException by default.

Applies to

Proizvod Verzije
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1