public void Decrypt(Stream inputStream, Stream outputStream) { ThrowIfDisposed(); if (inputStream == null) throw new ArgumentNullException("Input stream is null"); if (outputStream == null) throw new ArgumentNullException("Output stream is null"); var inputWrapper = new NotDisposableStream(inputStream); using (var reader = new BinaryReader(inputWrapper)) { algorithm.IV = reader.ReadBytes(algorithm.BlockSize / 8); using (var transform = algorithm.CreateDecryptor()) using (var decryptor = new CryptoStream(inputWrapper, transform, CryptoStreamMode.Read)) { var dataBuffer = new byte[BufferSize]; while (inputWrapper.Position < inputWrapper.Length) { var readed = decryptor.Read(dataBuffer, 0, BufferSize); outputStream.Write(dataBuffer, 0, readed); } } } }
public void Decrypt(Stream inputStream, Stream outputStream) { ThrowIfDisposed(); if (inputStream == null) { throw new ArgumentNullException("Input stream is null"); } if (outputStream == null) { throw new ArgumentNullException("Output stream is null"); } var inputWrapper = new NotDisposableStream(inputStream); using (var reader = new BinaryReader(inputWrapper)) { algorithm.IV = reader.ReadBytes(algorithm.BlockSize / 8); using (var transform = algorithm.CreateDecryptor()) using (var decryptor = new CryptoStream(inputWrapper, transform, CryptoStreamMode.Read)) { var dataBuffer = new byte[BufferSize]; while (inputWrapper.Position < inputWrapper.Length) { var readed = decryptor.Read(dataBuffer, 0, BufferSize); outputStream.Write(dataBuffer, 0, readed); } } } }
public void Encrypt(Stream inputStream, Stream outputStream) { ThrowIfDisposed(); if (inputStream == null) { throw new ArgumentNullException("Input stream is null"); } if (outputStream == null) { throw new ArgumentNullException("Output stream is null"); } var outputWrapper = new NotDisposableStream(outputStream); using (var transform = algorithm.CreateEncryptor()) using (var encrypter = new CryptoStream(outputWrapper, transform, CryptoStreamMode.Write)) using (var writer = new BinaryWriter(outputWrapper, Encoding.Unicode, true)) { writer.Write(algorithm.IV); var dataBuffer = new byte[BufferSize]; while (inputStream.Position < inputStream.Length) { var readed = inputStream.Read(dataBuffer, 0, BufferSize); encrypter.Write(dataBuffer, 0, readed); } } }
private void RaiseFileChanged(String fullPath, FileChangedDelegate action) { FileStream input; try { input = File.OpenRead(fullPath); } catch (Exception ex) { HandleError(ex); if (!File.Exists(fullPath)) { _changed.Remove(fullPath); } return; } _changed.Remove(fullPath); fullPath = PrepareFullPath(fullPath); using (input) { NotDisposableStream stream = new NotDisposableStream(input); foreach (FileChangedDelegate callback in action.Enumerate()) { try { input.Position = 0; callback(fullPath, stream); } catch (Exception ex) { HandleError(ex); } } } }
public void Encrypt <T>(T obj, Stream outputStream) { ThrowIfDisposed(); if (obj == null) { throw new ArgumentNullException("Input object is null"); } if (outputStream == null) { throw new ArgumentNullException("Output stream is null"); } var outputWrapper = new NotDisposableStream <Stream>(outputStream); using (var transform = algorithm.CreateEncryptor()) using (var encrypter = new CryptoStream(outputWrapper, transform, CryptoStreamMode.Write)) using (var writer = new BinaryWriter(outputWrapper, Encoding.Unicode, true)) { writer.Write(algorithm.IV); Serializer.Serialize(encrypter, obj); } }
public void Encrypt(Stream inputStream, Stream outputStream) { ThrowIfDisposed(); if (inputStream == null) throw new ArgumentNullException("Input stream is null"); if (outputStream == null) throw new ArgumentNullException("Output stream is null"); var outputWrapper = new NotDisposableStream(outputStream); using (var transform = algorithm.CreateEncryptor()) using (var encrypter = new CryptoStream(outputWrapper, transform, CryptoStreamMode.Write)) using (var writer = new BinaryWriter(outputWrapper, Encoding.Unicode, true)) { writer.Write(algorithm.IV); var dataBuffer = new byte[BufferSize]; while (inputStream.Position < inputStream.Length) { var readed = inputStream.Read(dataBuffer, 0, BufferSize); encrypter.Write(dataBuffer, 0, readed); } } }