Class AES_CTR
Class that can be used for AES CTR encryption / decryption
Implements
Inherited Members
Namespace: CS_AES_CTR
Assembly: .dll
Syntax
public sealed class AES_CTR : IDisposable
Constructors
| Edit this page View SourceAES_CTR(byte[], byte[], bool)
AES_CTR constructor
Declaration
public AES_CTR(byte[] key, byte[] initialCounter, bool littleEndian = false)
Parameters
Type | Name | Description |
---|---|---|
byte[] | key | Key as byte array. (128, 192 or 256 bits) |
byte[] | initialCounter | Initial counter as byte array. 16 bytes |
bool | littleEndian | Is initial counter little endian (default false) |
AES_CTR(ReadOnlySpan<byte>, ReadOnlySpan<byte>, bool)
AES_CTR constructor
Declaration
public AES_CTR(ReadOnlySpan<byte> key, ReadOnlySpan<byte> initialCounter, bool littleEndian = false)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<byte> | key | Key as readonlyspan. (128, 192 or 256 bits) |
ReadOnlySpan<byte> | initialCounter | Initial counter as readonlyspan. 16 bytes |
bool | littleEndian | Is initial counter little endian (default false) |
Fields
| Edit this page View SourceallowedCounterLength
What is allowed initial counter length in bytes
Declaration
public const int allowedCounterLength = 16
Field Value
Type | Description |
---|---|
int |
allowedKeyLengths
What are allowed key lengths in bytes (128, 192 and 256 bits)
Declaration
public static readonly ImmutableArray<int> allowedKeyLengths
Field Value
Type | Description |
---|---|
ImmutableArray<int> |
Methods
| Edit this page View SourceDecryptBytes(byte[], bool)
Decrypt arbitrary-length byte array (input), writing the resulting byte array that is allocated by method.
Declaration
public byte[] DecryptBytes(byte[] input, bool useSIMD = true)
Parameters
Type | Name | Description |
---|---|---|
byte[] | input | Input byte array |
bool | useSIMD | Use SIMD (true by default) |
Returns
Type | Description |
---|---|
byte[] | Byte array that contains decrypted bytes |
Remarks
Since this is symmetric operation, it doesn't really matter if you use Encrypt or Decrypt method
DecryptBytes(byte[], byte[], bool)
Decrypt arbitrary-length byte array (input), writing the resulting byte array to preallocated output buffer.
Declaration
public void DecryptBytes(byte[] output, byte[] input, bool useSIMD = true)
Parameters
Type | Name | Description |
---|---|---|
byte[] | output | Output byte array, must have enough bytes |
byte[] | input | Input byte array |
bool | useSIMD | Use SIMD (true by default) |
Remarks
Since this is symmetric operation, it doesn't really matter if you use Encrypt or Decrypt method
DecryptBytes(byte[], byte[], int, bool)
Decrypt arbitrary-length byte array (input), writing the resulting byte array to preallocated output buffer.
Declaration
public void DecryptBytes(byte[] output, byte[] input, int numBytes, bool useSIMD = true)
Parameters
Type | Name | Description |
---|---|---|
byte[] | output | Output byte array, must have enough bytes |
byte[] | input | Input byte array |
int | numBytes | Number of bytes to encrypt |
bool | useSIMD | Use SIMD (true by default) |
Remarks
Since this is symmetric operation, it doesn't really matter if you use Encrypt or Decrypt method
DecryptBytes(byte[], int, bool)
Decrypt arbitrary-length byte array (input), writing the resulting byte array that is allocated by method.
Declaration
public byte[] DecryptBytes(byte[] input, int numBytes, bool useSIMD = true)
Parameters
Type | Name | Description |
---|---|---|
byte[] | input | Input byte array |
int | numBytes | Number of bytes to encrypt |
bool | useSIMD | Use SIMD (true by default) |
Returns
Type | Description |
---|---|
byte[] | Byte array that contains decrypted bytes |
Remarks
Since this is symmetric operation, it doesn't really matter if you use Encrypt or Decrypt method
DecryptStream(Stream, Stream, int, bool)
Decrypt arbitrary-length byte stream (input), writing the resulting bytes to another stream (output)
Declaration
public void DecryptStream(Stream output, Stream input, int howManyBytesToProcessAtTime = 1024, bool useSIMD = true)
Parameters
Type | Name | Description |
---|---|---|
Stream | output | Output stream |
Stream | input | Input stream |
int | howManyBytesToProcessAtTime | How many bytes to read and write at time, default is 1024 |
bool | useSIMD | Use SIMD (true by default) |
DecryptStreamAsync(Stream, Stream, int, bool)
Async decrypt arbitrary-length byte stream (input), writing the resulting bytes to another stream (output)
Declaration
public Task DecryptStreamAsync(Stream output, Stream input, int howManyBytesToProcessAtTime = 1024, bool useSIMD = true)
Parameters
Type | Name | Description |
---|---|---|
Stream | output | Output stream |
Stream | input | Input stream |
int | howManyBytesToProcessAtTime | How many bytes to read and write at time, default is 1024 |
bool | useSIMD | Use SIMD (true by default) |
Returns
Type | Description |
---|---|
Task |
DecryptUTF8ByteArray(byte[], bool)
Decrypt UTF8 byte array to string.
Declaration
public string DecryptUTF8ByteArray(byte[] input, bool useSIMD = true)
Parameters
Type | Name | Description |
---|---|---|
byte[] | input | Byte array |
bool | useSIMD | Use SIMD (true by default) |
Returns
Type | Description |
---|---|
string | Byte array that contains encrypted bytes |
Remarks
Here you can NOT swap encrypt and decrypt methods, because of bytes-string transform
Dispose()
Clear and dispose of the internal state. Also request the GC not to call the finalizer, because all cleanup has been taken care of.
Declaration
public void Dispose()
EncryptBytes(byte[], bool)
Encrypt arbitrary-length byte array (input), writing the resulting byte array that is allocated by method.
Declaration
public byte[] EncryptBytes(byte[] input, bool useSIMD = true)
Parameters
Type | Name | Description |
---|---|---|
byte[] | input | Input byte array |
bool | useSIMD | Use SIMD (true by default) |
Returns
Type | Description |
---|---|
byte[] | Byte array that contains encrypted bytes |
Remarks
Since this is symmetric operation, it doesn't really matter if you use Encrypt or Decrypt method
EncryptBytes(byte[], byte[], bool)
Encrypt arbitrary-length byte array (input), writing the resulting byte array to preallocated output buffer.
Declaration
public void EncryptBytes(byte[] output, byte[] input, bool useSIMD = true)
Parameters
Type | Name | Description |
---|---|---|
byte[] | output | Output byte array, must have enough bytes |
byte[] | input | Input byte array |
bool | useSIMD | Use SIMD (true by default) |
Remarks
Since this is symmetric operation, it doesn't really matter if you use Encrypt or Decrypt method
EncryptBytes(byte[], byte[], int, bool)
Encrypt arbitrary-length byte array (input), writing the resulting byte array to preallocated output buffer.
Declaration
public void EncryptBytes(byte[] output, byte[] input, int numBytes, bool useSIMD = true)
Parameters
Type | Name | Description |
---|---|---|
byte[] | output | Output byte array, must have enough bytes |
byte[] | input | Input byte array |
int | numBytes | Number of bytes to encrypt |
bool | useSIMD | Use SIMD (true by default) |
Remarks
Since this is symmetric operation, it doesn't really matter if you use Encrypt or Decrypt method
EncryptBytes(byte[], int, bool)
Encrypt arbitrary-length byte array (input), writing the resulting byte array that is allocated by method.
Declaration
public byte[] EncryptBytes(byte[] input, int numBytes, bool useSIMD = true)
Parameters
Type | Name | Description |
---|---|---|
byte[] | input | Input byte array |
int | numBytes | Number of bytes to encrypt |
bool | useSIMD | Use SIMD (true by default) |
Returns
Type | Description |
---|---|
byte[] | Byte array that contains encrypted bytes |
Remarks
Since this is symmetric operation, it doesn't really matter if you use Encrypt or Decrypt method
EncryptStream(Stream, Stream, int, bool)
Encrypt arbitrary-length byte stream (input), writing the resulting bytes to another stream (output)
Declaration
public void EncryptStream(Stream output, Stream input, int howManyBytesToProcessAtTime = 1024, bool useSIMD = true)
Parameters
Type | Name | Description |
---|---|---|
Stream | output | Output stream |
Stream | input | Input stream |
int | howManyBytesToProcessAtTime | How many bytes to read and write at time, default is 1024 |
bool | useSIMD | Use SIMD (true by default) |
EncryptStreamAsync(Stream, Stream, int, bool)
Async encrypt arbitrary-length byte stream (input), writing the resulting bytes to another stream (output)
Declaration
public Task EncryptStreamAsync(Stream output, Stream input, int howManyBytesToProcessAtTime = 1024, bool useSIMD = true)
Parameters
Type | Name | Description |
---|---|---|
Stream | output | Output stream |
Stream | input | Input stream |
int | howManyBytesToProcessAtTime | How many bytes to read and write at time, default is 1024 |
bool | useSIMD | Use SIMD (true by default) |
Returns
Type | Description |
---|---|
Task |
EncryptString(string, bool)
Encrypt string as UTF8 byte array, returns byte array that is allocated by method.
Declaration
public byte[] EncryptString(string input, bool useSIMD = true)
Parameters
Type | Name | Description |
---|---|---|
string | input | Input string |
bool | useSIMD | Use SIMD (true by default) |
Returns
Type | Description |
---|---|
byte[] | Byte array that contains encrypted bytes |
Remarks
Here you can NOT swap encrypt and decrypt methods, because of bytes-string transform
~AES_CTR()
Clear and dispose of the internal variables. The finalizer is only called if Dispose() was never called on this cipher.
Declaration
protected ~AES_CTR()