Шифрование с помощью Rijndael без использования Application.DoEvents ()
Хотя я не понимаю, зачем вам это нужно, но да, вы можете сделать следующее:
using (System.Security.Cryptography.Rijndael rijndael = System.Security.Cryptography.Rijndael.Create()) {
rijndael.GenerateKey();
// Set your Key
// rijndael.Key = key;
rijndael.GenerateIV();
// Set your IV
// rijndael.IV = iv;
rijndael.BlockSize = 256; // this is what makes it different from AES
using (System.Security.Cryptography.ICryptoTransform transform = rijndael.CreateEncryptor()) {
var fileToBeEncrypted = System.IO.File.ReadAllBytes("Path");
transform.TransformFinalBlock(fileToBeEncrypted, 0, fileToBeEncrypted.Length);
}
}
Если ваш файл большой, то такой подход не будет очень эффективным.В этом случае вам лучше использовать поток, подобный следующему:
using (System.IO.FileStream inputFs = new System.IO.FileStream("inputPath", System.IO.FileMode.Open))
{
using (System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(inputFs, rijndael.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Read)) {
using (System.IO.FileStream outputFs = new System.IO.FileStream("outputPath", System.IO.FileMode.CreateNew)) {
cs.CopyTo(outputFs);
}
}
}