/// <summary> /// Decrypts and deserializes the input object using AES /// </summary> /// <param name="aes">The configured AES instance</param> /// <param name="input">The encrypted event object</param> /// <returns>The decrypted event object</returns> private static async Task <Event> Decrypt(Aes aes, EncryptedEvent input) { aes.IV = input.InitializationVector; var decryptor = aes.CreateDecryptor(); string output; using (MemoryStream memoryStream = new MemoryStream(input.Content)) { using CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read); using StreamReader streamReader = new StreamReader(cryptoStream); output = await streamReader.ReadToEndAsync(); } return(JsonConvert.DeserializeObject <Event>(output, _serializerSettings)); }
public async Task Add(string key, EncryptedEvent @event) { if (!string.IsNullOrEmpty(key)) { if (!_eventStreams.ContainsKey(key)) { _eventStreams.Add(key, new List <EncryptedEvent>()); } // Check the event is at a valid location of the stream if (_eventStreams[key].Count + 1 != @event.Location) { throw new EventConcurrencyException("Location of provided event is invalid"); } _eventStreams[key].Add(@event); await Task.Yield(); } else { throw new ArgumentNullException("Key cannot be null or empty"); } }