Is there a .NET encryption library that implements AES 256 encryption as a stream?

I would like to be able to encrypt / decrypt data as it streams to / from disk. I know that I can write my own Stream and implement encryption there, but I would not risk doing it wrong. Is there a library that works similarly to the following code?

byte[] encryptionKey = ; byte[] initVector = ; var fileStream = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write); var encryptionStream = new AesEncryptionStream(fileStream, initVector, encryptionKey); var gzStream = new GZipStream(encryptionStream, CompressionMode.Compress); var writer = new BinaryWriter(gzStream); 
+4
source share
1 answer

You are looking for the RijndaelManaged and CryptoStream classes:

 var aes = new RijndaelManaged { Key = ..., IV = ... }; using (var encryptor = aes.CreateEncryptor()) using (var cryptoStream = new CryptoStream(gzStream, encryptor, CryptoStreamMode.Write)) using (var writer = new BinaryWriter(cryptoStream)) { ... } 
+8
source

Source: https://habr.com/ru/post/1340195/


All Articles