public async Task WorkWithLargeFileTestAsync()
{
var progressEncrypt = new Progress<StreamCryptorTaskAsyncProgress>();
var progressDecrypt = new Progress<StreamCryptorTaskAsyncProgress>();
progressEncrypt.ProgressChanged +=
(s, e) => { Console.WriteLine("Encrypting: " + e.ProgressPercentage + "%\n"); };
progressDecrypt.ProgressChanged +=
(s, e) => { Console.WriteLine("Decrypting: " + e.ProgressPercentage + "%\n"); };
var testfileRaw = Path.Combine(TestContext.CurrentContext.TestDirectory, "Testfiles", "largefile.dat");
var testfileDecryptedFile = Path.Combine(TestContext.CurrentContext.TestDirectory, "Testfiles", "decrypted",
"largefile.dat");
var testfileDecryptedOutputDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "Testfiles",
"decrypted");
const string outputDirectory = "Testfiles";
const long testfileSizeGb = 1;
const string privateKey = "31d9040b00a170532929b37db0afcb989e4175f96e5f9667ee8cbf5706679a71";
const string publicKey = "6d0deec730700f9f60687a4e6e8755157ca22ea2f3815b9bf14b1fe9ae6a0b4d";
var keyPair = new KeyPair(Utilities.HexToBinary(publicKey), Utilities.HexToBinary(privateKey));
Console.Write("Generating {0} GB testfile . . .\n", testfileSizeGb);
var testTimer = new Stopwatch();
//generating
testTimer.Start();
var fs = new FileStream(testfileRaw, FileMode.CreateNew);
fs.Seek(testfileSizeGb*1024*1024*1024, SeekOrigin.Begin);
fs.WriteByte(0);
fs.Close();
testTimer.Stop();
var elapsedSeconds = testTimer.Elapsed.Seconds;
Console.Write("Time to generate testfile: {0} s\n", elapsedSeconds);
testTimer.Reset();
//encrypting
testTimer.Start();
Console.Write("Encrypting testfile . . .\n");
var encryptedFile =
await
Cryptor.EncryptFileWithStreamAsync(keyPair.PrivateKey, keyPair.PublicKey, keyPair.PublicKey,
testfileRaw, progressEncrypt);
testTimer.Stop();
elapsedSeconds = testTimer.Elapsed.Seconds;
Console.Write("Time to encrypt testfile: {0} s\n", elapsedSeconds);
testTimer.Reset();
//decrypting
testTimer.Start();
Console.Write("Decrypting testfile . . .\n");
await
Cryptor.DecryptFileWithStreamAsync(keyPair.PrivateKey,
Path.Combine(TestContext.CurrentContext.TestDirectory, outputDirectory, encryptedFile),
testfileDecryptedOutputDirectory, progressDecrypt);
testTimer.Stop();
elapsedSeconds = testTimer.Elapsed.Seconds;
Console.Write("Time to decrypt testfile: {0} s\n", elapsedSeconds);
testTimer.Reset();
//checksum
testTimer.Start();
Console.Write("Get checksum of testfiles . . .\n");
Assert.AreEqual(Utils.GetChecksum(testfileRaw), Utils.GetChecksum(testfileDecryptedFile));
testTimer.Stop();
elapsedSeconds = testTimer.Elapsed.Seconds;
Console.Write("Time to generate testfile checksums: {0} s\n", elapsedSeconds);
testTimer.Reset();
//clear garbage
File.Delete(testfileRaw);
File.Delete(Path.Combine(TestContext.CurrentContext.TestDirectory, outputDirectory, encryptedFile));
File.Delete(testfileDecryptedFile);
}