<PackageReference Include="Microsoft.Bcl.Cryptography" Version="11.0.0-rc.2.26504.105" />

System.Security.Cryptography.Hpke

public abstract class Hpke : IDisposable
Represents a Hybrid Public Key Encryption (HPKE) key.
public HpkeSuite Suite { get; }

Gets the cipher suite associated with this key.

protected Hpke(HpkeSuite suite)

Initializes a new instance of the Hpke class with the specified cipher suite.

public static Hpke DeriveKey(HpkeSuite suite, byte[] ikm)

Derives an HPKE key for the specified cipher suite from input keying material.

public static Hpke DeriveKey(HpkeSuite suite, ReadOnlySpan<byte> ikm)

Derives an HPKE key for the specified cipher suite from input keying material.

public static Hpke GenerateKey(HpkeSuite suite)

Generates a new HPKE key for the specified cipher suite.

public static Hpke ImportDecapsulationKey(HpkeSuite suite, byte[] source)

Imports an HPKE key pair from a serialized decapsulation key.

public static Hpke ImportDecapsulationKey(HpkeSuite suite, ReadOnlySpan<byte> source)

Imports an HPKE key pair from a serialized decapsulation key.

public static Hpke ImportEncapsulationKey(HpkeSuite suite, byte[] source)

Imports an HPKE key from a serialized encapsulation key.

public static Hpke ImportEncapsulationKey(HpkeSuite suite, ReadOnlySpan<byte> source)

Imports an HPKE key from a serialized encapsulation key.

public static bool IsSupported(HpkeSuite suite)

Determines whether the specified cipher suite is supported on the current platform.

public HpkeRecipient CreatePskRecipient(ReadOnlySpan<byte> encapsulatedSecret, ReadOnlySpan<byte> psk, ReadOnlySpan<byte> pskId, ReadOnlySpan<byte> info = default)

Creates an HPKE recipient context using a pre-shared key.

public HpkeRecipient CreatePskRecipient(byte[] encapsulatedSecret, byte[] psk, byte[] pskId, byte[] info = null)

Creates an HPKE recipient context using a pre-shared key.

protected abstract HpkeRecipient CreatePskRecipientCore(ReadOnlySpan<byte> encapsulatedSecret, ReadOnlySpan<byte> info, ReadOnlySpan<byte> psk, ReadOnlySpan<byte> pskId)

When overridden in a derived class, creates an HPKE recipient context using a pre-shared key.

public HpkeSender CreatePskSender(ReadOnlySpan<byte> psk, ReadOnlySpan<byte> pskId, out byte encapsulatedSecret, ReadOnlySpan<byte> info = default)

Creates an HPKE sender context using a pre-shared key.

public HpkeSender CreatePskSender(byte[] psk, byte[] pskId, out byte encapsulatedSecret, byte[] info = null)

Creates an HPKE sender context using a pre-shared key.

public HpkeSender CreatePskSender(ReadOnlySpan<byte> psk, ReadOnlySpan<byte> pskId, Span<byte> encapsulatedSecret, ReadOnlySpan<byte> info = default)

Creates an HPKE sender context using a pre-shared key and writes the encapsulated secret into the provided buffer.

protected abstract HpkeSender CreatePskSenderCore(Span<byte> encapsulatedSecret, ReadOnlySpan<byte> info, ReadOnlySpan<byte> psk, ReadOnlySpan<byte> pskId)

When overridden in a derived class, creates an HPKE sender context using a pre-shared key.

public HpkeRecipient CreateRecipient(ReadOnlySpan<byte> encapsulatedSecret, ReadOnlySpan<byte> info = default)

Creates an HPKE recipient context using Base mode.

public HpkeRecipient CreateRecipient(byte[] encapsulatedSecret, byte[] info = null)

Creates an HPKE recipient context using Base mode.

protected abstract HpkeRecipient CreateRecipientCore(ReadOnlySpan<byte> encapsulatedSecret, ReadOnlySpan<byte> info)

When overridden in a derived class, creates an HPKE recipient context using Base mode.

public HpkeSender CreateSender(out byte encapsulatedSecret, ReadOnlySpan<byte> info = default)

Creates an HPKE sender context using Base mode.

public HpkeSender CreateSender(Span<byte> encapsulatedSecret, ReadOnlySpan<byte> info = default)

Creates an HPKE sender context using Base mode and writes the encapsulated secret into the provided buffer.

protected abstract HpkeSender CreateSenderCore(Span<byte> encapsulatedSecret, ReadOnlySpan<byte> info)

When overridden in a derived class, creates an HPKE sender context using Base mode.

public void Dispose()

Releases all resources used by the Hpke 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 Hpke class.

public byte[] ExportDecapsulationKey()

Exports the decapsulation key.

public void ExportDecapsulationKey(Span<byte> destination)

Exports the decapsulation key into the provided buffer.

protected abstract void ExportDecapsulationKeyCore(Span<byte> destination)

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

public byte[] ExportEncapsulationKey()

Exports the encapsulation key.

public void ExportEncapsulationKey(Span<byte> destination)

Exports the encapsulation key into the provided buffer.

protected abstract void ExportEncapsulationKeyCore(Span<byte> destination)

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

public byte[] Open(ReadOnlySpan<byte> encapsulatedSecret, ReadOnlySpan<byte> ciphertext, ReadOnlySpan<byte> associatedData = default, ReadOnlySpan<byte> info = default)

Decrypts a single HPKE ciphertext using Base mode.

public byte[] Open(byte[] encapsulatedSecret, byte[] ciphertext, byte[] associatedData = null, byte[] info = null)

Decrypts a single HPKE ciphertext using Base mode.

public void Open(ReadOnlySpan<byte> encapsulatedSecret, ReadOnlySpan<byte> ciphertext, Span<byte> plaintext, ReadOnlySpan<byte> associatedData = default, ReadOnlySpan<byte> info = default)

Decrypts a single HPKE ciphertext into the provided buffer using Base mode.

protected abstract void OpenCore(ReadOnlySpan<byte> encapsulatedSecret, ReadOnlySpan<byte> ciphertext, Span<byte> plaintext, ReadOnlySpan<byte> associatedData, ReadOnlySpan<byte> info)

When overridden in a derived class, decrypts a single HPKE ciphertext using Base mode.

public void Seal(ReadOnlySpan<byte> plaintext, out byte encapsulatedSecret, out byte ciphertext, ReadOnlySpan<byte> associatedData = default, ReadOnlySpan<byte> info = default)

Encrypts a single message using Base mode.

public void Seal(byte[] plaintext, out byte encapsulatedSecret, out byte ciphertext, byte[] associatedData = null, byte[] info = null)

Encrypts a single message using Base mode.

public void Seal(ReadOnlySpan<byte> plaintext, Span<byte> encapsulatedSecret, Span<byte> ciphertext, ReadOnlySpan<byte> associatedData = default, ReadOnlySpan<byte> info = default)

Encrypts a single message into the provided buffers using Base mode.

protected abstract void SealCore(ReadOnlySpan<byte> plaintext, Span<byte> encapsulatedSecret, Span<byte> ciphertext, ReadOnlySpan<byte> associatedData, ReadOnlySpan<byte> info)

When overridden in a derived class, encrypts a single message using Base mode.