Перейти к основному содержимому

PacketCipher

abstract class

Represents an AES/CFB8 stream cipher that transforms protocol bytes in place.

Declaration

public abstract class PacketCipher
NamespaceMcProtoNet.Transport.Cryptography
AssemblyMcProtoNet.Transport.dll
Sourcesrc/McProtoNet.Transport/Cryptography/PacketCipher.cs#L11 ↗

Remarks

A cipher carries the feedback register of the stream it serves, so one instance belongs to one direction of one connection and must be used by one thread at a time. The concrete implementation is chosen at creation time: an x86 AES-NI core, an ARM64 NEON core, or a scalar fallback.

Fields

SignatureDescription
const int SharedSecretLength = 16The required length of the shared secret, in bytes.

SharedSecretLength

public const int SharedSecretLength = 16

The required length of the shared secret, in bytes.

Returns: Int32

Methods

SignatureDescription
static PacketCipher CreateDecryptor(ReadOnlySpan<byte> sharedSecret)Creates a cipher that decrypts incoming bytes with the specified shared secret.
static PacketCipher CreateEncryptor(ReadOnlySpan<byte> sharedSecret)Creates a cipher that encrypts outgoing bytes with the specified shared secret.
void Dispose()Releases all resources used by the current instance of the PacketCipher class.
void Dispose(bool disposing)Releases the unmanaged resources used by the PacketCipher and optionally releases the managed resources.
void Transform(Span<byte> buffer)When overridden in a derived class, transforms the specified buffer in place and advances the cipher state by its length.

CreateDecryptor(ReadOnlySpan<byte>)

public static PacketCipher CreateDecryptor(ReadOnlySpan<byte> sharedSecret)

Creates a cipher that decrypts incoming bytes with the specified shared secret.

Parameters: sharedSecret (ReadOnlySpan<Byte>)

Returns: PacketCipher - A new PacketCipher that decrypts.

Exceptions: ArgumentException - <code class="paramref">sharedSecret</code> is not PacketCipher.SharedSecretLength bytes long.

CreateEncryptor(ReadOnlySpan<byte>)

public static PacketCipher CreateEncryptor(ReadOnlySpan<byte> sharedSecret)

Creates a cipher that encrypts outgoing bytes with the specified shared secret.

Parameters: sharedSecret (ReadOnlySpan<Byte>)

Returns: PacketCipher - A new PacketCipher that encrypts.

Exceptions: ArgumentException - <code class="paramref">sharedSecret</code> is not PacketCipher.SharedSecretLength bytes long.

Dispose()

public void Dispose()

Releases all resources used by the current instance of the PacketCipher class.

Dispose(bool)

protected virtual void Dispose(bool disposing)

Releases the unmanaged resources used by the PacketCipher and optionally releases the managed resources.

Parameters: disposing (Boolean)

Transform(Span<byte>)

public abstract void Transform(Span<byte> buffer)

When overridden in a derived class, transforms the specified buffer in place and advances the cipher state by its length.

Parameters: buffer (Span<Byte>)