<PackageReference Include="Microsoft.Bcl.Cryptography" Version="10.0.11" />

System.Security.Cryptography.MLKem

public abstract class MLKem : IDisposable
Represents an ML-KEM key.
public static bool IsSupported { get; }

Gets a value that indicates whether the algorithm is supported on the current platform.

public MLKemAlgorithm Algorithm { get; }

Gets the specific ML-KEM algorithm for this key.

protected MLKem(MLKemAlgorithm algorithm)

Initializes a new instance of the MLKem class.

public static MLKem GenerateKey(MLKemAlgorithm algorithm)

Generates a new ML-KEM key.

public static MLKem ImportDecapsulationKey(MLKemAlgorithm algorithm, ReadOnlySpan<byte> source)

Imports an ML-KEM key from a decapsulation key.

public static MLKem ImportDecapsulationKey(MLKemAlgorithm algorithm, byte[] source)

Imports an ML-KEM key from a decapsulation key.

public static MLKem ImportEncapsulationKey(MLKemAlgorithm algorithm, ReadOnlySpan<byte> source)

Imports an ML-KEM key from a encapsulation key.

public static MLKem ImportEncapsulationKey(MLKemAlgorithm algorithm, byte[] source)

Imports an ML-KEM key from a encapsulation key.

public static MLKem ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<byte> passwordBytes, ReadOnlySpan<byte> source)

Imports an ML-KEM private key from a PKCS#8 EncryptedPrivateKeyInfo structure.

public static MLKem ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<char> password, ReadOnlySpan<byte> source)

Imports an ML-KEM private key from a PKCS#8 EncryptedPrivateKeyInfo structure.

public static MLKem ImportEncryptedPkcs8PrivateKey(string password, byte[] source)

Imports an ML-KEM private key from a PKCS#8 EncryptedPrivateKeyInfo structure.

public static MLKem ImportFromEncryptedPem(ReadOnlySpan<char> source, ReadOnlySpan<char> password)

Imports an ML-KEM key from an encrypted RFC 7468 PEM-encoded string.

public static MLKem ImportFromEncryptedPem(ReadOnlySpan<char> source, ReadOnlySpan<byte> passwordBytes)

Imports an ML-KEM key from an encrypted RFC 7468 PEM-encoded string.

public static MLKem ImportFromEncryptedPem(string source, string password)

public static MLKem ImportFromEncryptedPem(string source, byte[] passwordBytes)

public static MLKem ImportFromPem(ReadOnlySpan<char> source)

Imports an ML-KEM key from an RFC 7468 PEM-encoded string.

public static MLKem ImportFromPem(string source)

public static MLKem ImportPkcs8PrivateKey(ReadOnlySpan<byte> source)

Imports an ML-KEM private key from a PKCS#8 PrivateKeyInfo structure.

public static MLKem ImportPkcs8PrivateKey(byte[] source)

public static MLKem ImportPrivateSeed(MLKemAlgorithm algorithm, ReadOnlySpan<byte> source)

Imports an ML-KEM key from its private seed value.

public static MLKem ImportPrivateSeed(MLKemAlgorithm algorithm, byte[] source)

Imports an ML-KEM key from its private seed value.

public static MLKem ImportSubjectPublicKeyInfo(ReadOnlySpan<byte> source)

Imports an ML-KEM encapsulation key from an X.509 SubjectPublicKeyInfo structure.

public static MLKem ImportSubjectPublicKeyInfo(byte[] source)

public void Decapsulate(ReadOnlySpan<byte> ciphertext, Span<byte> sharedSecret)

Decapsulates a shared secret from a provided ciphertext.

public byte[] Decapsulate(byte[] ciphertext)

Decapsulates a shared secret from a provided ciphertext.

protected abstract void DecapsulateCore(ReadOnlySpan<byte> ciphertext, Span<byte> sharedSecret)

When overridden in a derived class, decapsulates a shared secret from a provided ciphertext.

public void Dispose()

Releases all resources used by the MLKem class.

protected virtual void Dispose(bool disposing)

Called by the Dispose() and Finalize() methods to release the managed and unmanaged resources used by the current instance of the MLKem class.

public void Encapsulate(Span<byte> ciphertext, Span<byte> sharedSecret)

Creates an encapsulation ciphertext and shared secret, writing them into the provided buffers.

public void Encapsulate(out byte ciphertext, out byte sharedSecret)

Creates an encapsulation ciphertext and shared secret.

protected abstract void EncapsulateCore(Span<byte> ciphertext, Span<byte> sharedSecret)

When overridden in a derived class, creates an encapsulation ciphertext and shared secret, writing them into the provided buffers.

public void ExportDecapsulationKey(Span<byte> destination)

Exports the decapsulation key into the provided buffer.

public byte[] ExportDecapsulationKey()

Exports the decapsulation key.

protected abstract void ExportDecapsulationKeyCore(Span<byte> destination)

When overridden in a derived class, exports the decapsulation key into the provided buffer.

public void ExportEncapsulationKey(Span<byte> destination)

Exports the encapsulation key into the provided buffer.

public byte[] ExportEncapsulationKey()

Exports the encapsulation key.

protected abstract void ExportEncapsulationKeyCore(Span<byte> destination)

When overridden in a derived class, exports the encapsulation key into the provided buffer.

public byte[] ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<byte> passwordBytes, PbeParameters pbeParameters)

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

public byte[] ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<char> password, PbeParameters pbeParameters)

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

public byte[] ExportEncryptedPkcs8PrivateKey(string password, PbeParameters pbeParameters)

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

public string ExportEncryptedPkcs8PrivateKeyPem(ReadOnlySpan<byte> passwordBytes, PbeParameters pbeParameters)

Exports the current key in a PEM-encoded representation of the PKCS#8 EncryptedPrivateKeyInfo representation of this key, using a byte-based password.

public string ExportEncryptedPkcs8PrivateKeyPem(ReadOnlySpan<char> password, PbeParameters pbeParameters)

Exports the current key in a PEM-encoded representation of the PKCS#8 EncryptedPrivateKeyInfo representation of this key, using a char-based password.

public string ExportEncryptedPkcs8PrivateKeyPem(string password, PbeParameters pbeParameters)

Exports the current key in a PEM-encoded representation of the PKCS#8 EncryptedPrivateKeyInfo representation of this key, using a string password.

public byte[] ExportPkcs8PrivateKey()

Export the current key in the PKCS#8 PrivateKeyInfo format.

public string ExportPkcs8PrivateKeyPem()

Exports the current key in a PEM-encoded representation of the PKCS#8 PrivateKeyInfo format.

public void ExportPrivateSeed(Span<byte> destination)

Exports the private seed into the provided buffer.

public byte[] ExportPrivateSeed()

Exports the private seed.

protected abstract void ExportPrivateSeedCore(Span<byte> destination)

When overridden in a derived class, exports the private seed into the provided buffer.

Exports the public-key portion of the current key in the X.509 SubjectPublicKeyInfo format.

Exports the public-key portion of the current key in a PEM-encoded representation of the X.509 SubjectPublicKeyInfo format.

public bool TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<char> password, PbeParameters pbeParameters, Span<byte> destination, out int bytesWritten)

Attempts to export the current key in the PKCS#8 EncryptedPrivateKeyInfo format into a provided buffer, using a char-based password.

public bool TryExportEncryptedPkcs8PrivateKey(string password, PbeParameters pbeParameters, Span<byte> destination, out int bytesWritten)

Attempts to export the current key in the PKCS#8 EncryptedPrivateKeyInfo format into a provided buffer, using a char-based password.

public bool TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<byte> passwordBytes, PbeParameters pbeParameters, Span<byte> destination, out int bytesWritten)

Attempts to export the current key in the PKCS#8 EncryptedPrivateKeyInfo format into a provided buffer, using a byte-based password.

public bool TryExportPkcs8PrivateKey(Span<byte> destination, out int bytesWritten)

Attempts to export the current key in the PKCS#8 PrivateKeyInfo format into the provided buffer.

protected abstract bool TryExportPkcs8PrivateKeyCore(Span<byte> destination, out int bytesWritten)

When overridden in a derived class, attempts to export the current key in the PKCS#8 PrivateKeyInfo format into the provided buffer.

public bool TryExportSubjectPublicKeyInfo(Span<byte> destination, out int bytesWritten)

Attempts to export the public-key portion of the current key in the X.509 SubjectPublicKeyInfo format into the provided buffer.