5using System.Threading.Tasks;
28 this.aes = Aes.Create();
29 this.aes.BlockSize = 128;
30 this.aes.KeySize = 256;
31 this.aes.Mode = CipherMode.CBC;
32 this.aes.Padding = PaddingMode.None;
78 public override byte[]
GetIV(
string Id,
string Type,
string From,
string To, uint Counter)
81 Array.Resize(ref IV, 16);
83 IV[12] = (byte)Counter;
85 IV[13] = (byte)Counter;
87 IV[14] = (byte)Counter;
89 IV[15] = (byte)Counter;
101 return (ContentLength + 15L) & ~0xfL;
113 public override byte[]
Encrypt(
byte[] Data,
byte[] Key,
byte[] IV,
byte[] AssociatedData,
116 byte[] Encrypted = base.Encrypt(Data, Key, IV, AssociatedData, FillAlgorithm);
120 using ICryptoTransform Aes = this.aes.CreateEncryptor(Key, IV);
122 Encrypted = Aes.TransformFinalBlock(Encrypted, 0, Encrypted.Length);
136 public override byte[]
Decrypt(
byte[] Data,
byte[] Key,
byte[] IV,
byte[] AssociatedData)
140 using ICryptoTransform Aes = this.aes.CreateDecryptor(Key, IV);
142 Data = Aes.TransformFinalBlock(Data, 0, Data.Length);
145 return base.Decrypt(Data, Key, IV, AssociatedData);
156 public override async Task
Encrypt(Stream Data, Stream Encrypted,
byte[] Key,
byte[] IV,
byte[] AssociatedData)
159 ICryptoTransform Aes =
null;
163 await base.Encrypt(Data, PreEncrypt, Key, IV, AssociatedData);
164 PreEncrypt.Position = 0;
168 Aes = this.aes.CreateEncryptor(Key, IV);
188 public override async Task<Stream>
Decrypt(Stream Data,
byte[] Key,
byte[] IV,
byte[] AssociatedData)
190 ICryptoTransform Aes =
null;
197 Aes = this.aes.CreateDecryptor(Key, IV);
202 Decrypted.Position = 0;
203 return await base.Decrypt(Decrypted, Key, IV, AssociatedData);
220 this.aes.GenerateKey();
Helps with common XML-related tasks.
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Implements support for the AES-256 cipher in hybrid End-to-End encryption schemes.
override void Dispose()
IDisposable.Dispose
override bool Supported(XmlElement E2e)
If the symmetric cipher is supported by a remote endpoint.
override byte[] Decrypt(byte[] Data, byte[] Key, byte[] IV, byte[] AssociatedData)
Decrypts binary data
override byte[] Encrypt(byte[] Data, byte[] Key, byte[] IV, byte[] AssociatedData, E2eBufferFillAlgorithm FillAlgorithm)
Encrypts binary data
override long GetEncryptedLength(long ContentLength)
Calculates the minimum size of encrypted data, given the size of the content.
Aes256()
Implements support for the AES-256 cipher in hybrid End-to-End encryption schemes.
override byte[] GenerateKey()
Generates a new key. Used when the asymmetric cipher cannot calculate a shared secret.
Aes aes
AES encryption object
override byte[] GetIV(string Id, string Type, string From, string To, uint Counter)
Gets an Initiation Vector from stanza attributes.
override async Task Encrypt(Stream Data, Stream Encrypted, byte[] Key, byte[] IV, byte[] AssociatedData)
Encrypts binary data
override async Task< Stream > Decrypt(Stream Data, byte[] Key, byte[] IV, byte[] AssociatedData)
Decrypts binary data
override string LocalName
Local name of the E2E symmetric cipher
override IE2eSymmetricCipher CreteNew()
Creates a new symmetric cipher object with the same settings as the current object.
Abstract base class for symmetric ciphers.
Manages a temporary stream. Contents is kept in-memory, if below a memory threshold,...
override void Dispose(bool disposing)
Releases the unmanaged resources used by the System.IO.Stream and optionally releases the managed res...
Helper methods for encrypting and decrypting streams of data.
static Task CryptoTransform(ICryptoTransform Transform, Stream Source, Stream Destination)
Transforms a stream of data.
Contains methods for simple hash calculations.
static byte[] ComputeSHA256Hash(byte[] Data)
Computes the SHA-256 hash of a block of binary data.
Interface for symmetric ciphers.
E2eBufferFillAlgorithm
How buffers are filler before E2E Encryption is performed.