Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Security.​Cryptography.​MLKem

Assembly: System.Security.Cryptography

Inheritance: object → MLKem

Implemented Interfaces

Represents an ML-KEM key.

Properties

Algorithm
Gets the specific ML-KEM algorithm for this key.
public static bool
IsSupported
Gets a value that indicates whether the algorithm is supported on the current platform.

Methods

public byte[]
Decapsulate​(byte[] ciphertext)
Decapsulates a shared secret from a provided ciphertext.
Returns The shared secret.
ciphertext The ciphertext.
public void
Decapsulate​(ReadOnlySpan<​byte> ciphertext, Span<​byte> sharedSecret)
Decapsulates a shared secret from a provided ciphertext.
ciphertext The ciphertext.
sharedSecret The buffer to receive the shared secret.
protected void
DecapsulateCore​(ReadOnlySpan<​byte> ciphertext, Span<​byte> sharedSecret)
When overridden in a derived class, decapsulates a shared secret from a provided ciphertext.
ciphertext The ciphertext.
sharedSecret The buffer to receive the shared secret.
public void
Dispose​()
Releases all resources used by the <see cref="T:System.Security.Cryptography.MLKem" /> class.
protected void
Dispose​(bool disposing)
<para>Called by the <c>Dispose()</c> and <c>Finalize()</c> methods to release the managed and unmanaged resources used by the current instance of the <see cref="T:System.Security.Cryptography.MLKem" /> class.</para>
disposing <para> <see langword="true" /> to release managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.</para>
public void
Encapsulate​(Byte[]& ciphertext, Byte[]& sharedSecret)
public void
Encapsulate​(Span<​byte> ciphertext, Span<​byte> sharedSecret)
Creates an encapsulation ciphertext and shared secret, writing them into the provided buffers.
ciphertext The buffer to receive the ciphertext.
sharedSecret The buffer to receive the shared secret.
protected void
EncapsulateCore​(Span<​byte> ciphertext, Span<​byte> sharedSecret)
<para>When overridden in a derived class, creates an encapsulation ciphertext and shared secret, writing them into the provided buffers.</para>
ciphertext The buffer to receive the ciphertext.
sharedSecret The buffer to receive the shared secret.
public byte[]
ExportDecapsulationKey​()
Exports the decapsulation key.
Returns The decapsulation key.
public void
ExportDecapsulationKey​(Span<​byte> destination)
Exports the decapsulation key into the provided buffer.
destination The buffer to receive the decapsulation key.
protected void
ExportDecapsulationKeyCore​(Span<​byte> destination)
When overridden in a derived class, exports the decapsulation key into the provided buffer.
destination The buffer to receive the decapsulation key.
public byte[]
ExportEncapsulationKey​()
Exports the encapsulation key.
Returns The encapsulation key.
public void
ExportEncapsulationKey​(Span<​byte> destination)
Exports the encapsulation key into the provided buffer.
destination The buffer to receive the encapsulation key.
protected void
ExportEncapsulationKeyCore​(Span<​byte> destination)
When overridden in a derived class, exports the encapsulation key into the provided buffer.
destination The buffer to receive the encapsulation key.
public byte[]
ExportEncryptedPkcs8PrivateKey​(ReadOnlySpan<​byte> passwordBytes, PbeParameters pbeParameters)
Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a byte-based password.
Returns A byte array containing the PKCS#8 EncryptedPrivateKeyInfo representation of this key.
passwordBytes The password to use when encrypting the key material.
pbeParameters The password-based encryption (PBE) parameters to use when encrypting the key material.
public byte[]
ExportEncryptedPkcs8PrivateKey​(ReadOnlySpan<​char> password, PbeParameters pbeParameters)
Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a char-based password.
Returns A byte array containing the PKCS#8 EncryptedPrivateKeyInfo representation of this key.
password The password to use when encrypting the key material.
pbeParameters The password-based encryption (PBE) parameters to use when encrypting the key material.
public byte[]
ExportEncryptedPkcs8PrivateKey​(string password, PbeParameters pbeParameters)
Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a char-based password.
Returns A byte array containing the PKCS#8 EncryptedPrivateKeyInfo representation of this key.
password The password to use when encrypting the key material.
pbeParameters The password-based encryption (PBE) parameters to use when encrypting the key material.
public string
ExportEncryptedPkcs8PrivateKeyPem​(ReadOnlySpan<​byte> passwordBytes, PbeParameters pbeParameters)
<para>Exports the current key in a PEM-encoded representation of the PKCS#8 EncryptedPrivateKeyInfo representation of this key, using a byte-based password.</para>
Returns A string containing the PEM-encoded PKCS#8 EncryptedPrivateKeyInfo.
passwordBytes The bytes to use as a password when encrypting the key material.
pbeParameters The password-based encryption (PBE) parameters to use when encrypting the key material.
public string
ExportEncryptedPkcs8PrivateKeyPem​(ReadOnlySpan<​char> password, PbeParameters pbeParameters)
<para>Exports the current key in a PEM-encoded representation of the PKCS#8 EncryptedPrivateKeyInfo representation of this key, using a char-based password.</para>
Returns A string containing the PEM-encoded PKCS#8 EncryptedPrivateKeyInfo.
password The password to use when encrypting the key material.
pbeParameters The password-based encryption (PBE) parameters to use when encrypting the key material.
public string
ExportEncryptedPkcs8PrivateKeyPem​(string password, PbeParameters pbeParameters)
<para>Exports the current key in a PEM-encoded representation of the PKCS#8 EncryptedPrivateKeyInfo representation of this key, using a string password.</para>
Returns A string containing the PEM-encoded PKCS#8 EncryptedPrivateKeyInfo.
password The password to use when encrypting the key material.
pbeParameters The password-based encryption (PBE) parameters to use when encrypting the key material.
public byte[]
ExportPkcs8PrivateKey​()
Export the current key in the PKCS#8 PrivateKeyInfo format.
Returns A byte array containing the PKCS#8 PrivateKeyInfo representation of this key.
public string
ExportPkcs8PrivateKeyPem​()
Exports the current key in a PEM-encoded representation of the PKCS#8 PrivateKeyInfo format.
Returns A string containing the PEM-encoded representation of the PKCS#8 PrivateKeyInfo.
public byte[]
ExportPrivateSeed​()
Exports the private seed.
Returns The private seed.
public void
ExportPrivateSeed​(Span<​byte> destination)
Exports the private seed into the provided buffer.
destination The buffer to receive the private seed.
protected void
ExportPrivateSeedCore​(Span<​byte> destination)
When overridden in a derived class, exports the private seed into the provided buffer.
destination The buffer to receive the private seed.
public byte[]
ExportSubjectPublicKeyInfo​()
Exports the public-key portion of the current key in the X.509 SubjectPublicKeyInfo format.
Returns A byte array containing the X.509 SubjectPublicKeyInfo representation of the public-key portion of this key.
public string
ExportSubjectPublicKeyInfoPem​()
<para>Exports the public-key portion of the current key in a PEM-encoded representation of the X.509 SubjectPublicKeyInfo format.</para>
Returns <para>A string containing the PEM-encoded representation of the X.509 SubjectPublicKeyInfo representation of the public-key portion of this key.</para>
public static MLKem
GenerateKey​(MLKemAlgorithm algorithm)
Generates a new ML-KEM key.
Returns The generated key.
algorithm An algorithm identifying what kind of ML-KEM key to generate.
public static MLKem
ImportDecapsulationKey​(MLKemAlgorithm algorithm, byte[] source)
Imports an ML-KEM key from a decapsulation key.
Returns The imported key.
algorithm The specific ML-KEM algorithm for this key.
source The decapsulation key.
public static MLKem
ImportDecapsulationKey​(MLKemAlgorithm algorithm, ReadOnlySpan<​byte> source)
Imports an ML-KEM key from a decapsulation key.
Returns The imported key.
algorithm The specific ML-KEM algorithm for this key.
source The decapsulation key.
public static MLKem
ImportEncapsulationKey​(MLKemAlgorithm algorithm, byte[] source)
Imports an ML-KEM key from a encapsulation key.
Returns The imported key.
algorithm The specific ML-KEM algorithm for this key.
source The encapsulation key.
public static MLKem
ImportEncapsulationKey​(MLKemAlgorithm algorithm, ReadOnlySpan<​byte> source)
Imports an ML-KEM key from a encapsulation key.
Returns The imported key.
algorithm The specific ML-KEM algorithm for this key.
source The encapsulation key.
public static MLKem
ImportEncryptedPkcs8PrivateKey​(ReadOnlySpan<​byte> passwordBytes, ReadOnlySpan<​byte> source)
Imports an ML-KEM private key from a PKCS#8 EncryptedPrivateKeyInfo structure.
Returns The imported key.
passwordBytes The bytes to use as a password when decrypting the key material.
source The bytes of a PKCS#8 EncryptedPrivateKeyInfo structure in the ASN.1-BER encoding.
public static MLKem
ImportEncryptedPkcs8PrivateKey​(ReadOnlySpan<​char> password, ReadOnlySpan<​byte> source)
Imports an ML-KEM private key from a PKCS#8 EncryptedPrivateKeyInfo structure.
Returns The imported key.
password The password to use when decrypting the key material.
source The bytes of a PKCS#8 EncryptedPrivateKeyInfo structure in the ASN.1-BER encoding.
public static MLKem
ImportEncryptedPkcs8PrivateKey​(string password, byte[] source)
Imports an ML-KEM private key from a PKCS#8 EncryptedPrivateKeyInfo structure.
Returns The imported key.
password The password to use when decrypting the key material.
source The bytes of a PKCS#8 EncryptedPrivateKeyInfo structure in the ASN.1-BER encoding.
public static MLKem
ImportFromEncryptedPem​(ReadOnlySpan<​char> source, ReadOnlySpan<​byte> passwordBytes)
Imports an ML-KEM key from an encrypted RFC 7468 PEM-encoded string.
source The PEM text of the encrypted key to import.
passwordBytes The password to use for decrypting the key material.
public static MLKem
ImportFromEncryptedPem​(ReadOnlySpan<​char> source, ReadOnlySpan<​char> password)
Imports an ML-KEM key from an encrypted RFC 7468 PEM-encoded string.
source The PEM text of the encrypted key to import.
password The password to use for decrypting the key material.
public static MLKem
ImportFromEncryptedPem​(string source, byte[] passwordBytes)
Imports an ML-KEM key from an encrypted RFC 7468 PEM-encoded string.
source The PEM text of the encrypted key to import.
passwordBytes The password to use for decrypting the key material.
public static MLKem
ImportFromEncryptedPem​(string source, string password)
Imports an ML-KEM key from an encrypted RFC 7468 PEM-encoded string.
source The PEM text of the encrypted key to import.
password The password to use for decrypting the key material.
public static MLKem
ImportFromPem​(ReadOnlySpan<​char> source)
Imports an ML-KEM key from an RFC 7468 PEM-encoded string.
Returns The imported ML-KEM key.
source The text of the PEM key to import.
public static MLKem
ImportFromPem​(string source)
Imports an ML-KEM key from an RFC 7468 PEM-encoded string.
Returns The imported ML-KEM key.
source The text of the PEM key to import.
public static MLKem
ImportPkcs8PrivateKey​(byte[] source)
Imports an ML-KEM private key from a PKCS#8 PrivateKeyInfo structure.
Returns The imported key.
source The bytes of a PKCS#8 PrivateKeyInfo structure in the ASN.1-BER encoding.
public static MLKem
ImportPkcs8PrivateKey​(ReadOnlySpan<​byte> source)
Imports an ML-KEM private key from a PKCS#8 PrivateKeyInfo structure.
Returns The imported key.
source The bytes of a PKCS#8 PrivateKeyInfo structure in the ASN.1-BER encoding.
public static MLKem
ImportPrivateSeed​(MLKemAlgorithm algorithm, byte[] source)
Imports an ML-KEM key from its private seed value.
Returns The imported key.
algorithm The specific ML-KEM algorithm for this key.
source The private seed.
public static MLKem
ImportPrivateSeed​(MLKemAlgorithm algorithm, ReadOnlySpan<​byte> source)
Imports an ML-KEM key from its private seed value.
Returns The imported key.
algorithm The specific ML-KEM algorithm for this key.
source The private seed.
public static MLKem
ImportSubjectPublicKeyInfo​(byte[] source)
Imports an ML-KEM encapsulation key from an X.509 SubjectPublicKeyInfo structure.
Returns The imported key.
source The bytes of an X.509 SubjectPublicKeyInfo structure in the ASN.1-DER encoding.
public static MLKem
ImportSubjectPublicKeyInfo​(ReadOnlySpan<​byte> source)
Imports an ML-KEM encapsulation key from an X.509 SubjectPublicKeyInfo structure.
Returns The imported key.
source The bytes of an X.509 SubjectPublicKeyInfo structure in the ASN.1-DER encoding.
public bool
TryExportEncryptedPkcs8PrivateKey​(ReadOnlySpan<​byte> passwordBytes, PbeParameters pbeParameters, Span<​byte> destination, Int32& bytesWritten)
public bool
TryExportEncryptedPkcs8PrivateKey​(ReadOnlySpan<​char> password, PbeParameters pbeParameters, Span<​byte> destination, Int32& bytesWritten)
public bool
TryExportEncryptedPkcs8PrivateKey​(string password, PbeParameters pbeParameters, Span<​byte> destination, Int32& bytesWritten)
public bool
TryExportPkcs8PrivateKey​(Span<​byte> destination, Int32& bytesWritten)
protected bool
TryExportPkcs8PrivateKeyCore​(Span<​byte> destination, Int32& bytesWritten)
public bool
TryExportSubjectPublicKeyInfo​(Span<​byte> destination, Int32& bytesWritten)
public bool
Equals​(object obj)
Inherited from object
protected void
Finalize​()
Inherited from object
public int
GetHashCode​()
Inherited from object
public Type
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object
public string
ToString​()
Inherited from object