Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

encryption

aes

I'd like to be able to encrypt / decrypt data as it's streamed to/from disk. I know I could write my own Stream and implement the encryption there, but I'd rather not risk doing it wrong. Is there a library that works in a similar way 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);
like image 707
ScArcher2 Avatar asked Feb 17 '11 16:02

ScArcher2


People also ask

Can you hack AES 256?

AES 256 is virtually impenetrable using brute-force methods. While a 56-bit DES key can be cracked in less than a day, AES would take billions of years to break using current computing technology. Hackers would be foolish to even attempt this type of attack. Nevertheless, no encryption system is entirely secure.

Is AES 256 good encryption?

AES-256, which has a key length of 256 bits, supports the largest bit size and is practically unbreakable by brute force based on current computing power, making it the strongest encryption standard.

Does AES need salt?

AES doesn't have a concept of a salt. It just takes data, and a key. For the same input, it will always generate the same output. How you combine your message with your salt is up to you.


1 Answers

You're 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)) {
    ...
}
like image 136
SLaks Avatar answered Oct 06 '22 01:10

SLaks