public async Task WorkWithSmallFileTesAsynct()
{
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", "verysmallfile.dat");
var testfileDecryptedFile = Path.Combine(TestContext.CurrentContext.TestDirectory, "Testfiles", "decrypted",
"verysmallfile.dat");
var testfileDecryptedOutputDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "Testfiles",
"decrypted");
const string outputDirectory = "Testfiles";
const long testfileSizeKb = 1024;
const string privateKey = "31d9040b00a170532929b37db0afcb989e4175f96e5f9667ee8cbf5706679a71";
const string publicKey = "6d0deec730700f9f60687a4e6e8755157ca22ea2f3815b9bf14b1fe9ae6a0b4d";
var keyPair = new KeyPair(Utilities.HexToBinary(publicKey), Utilities.HexToBinary(privateKey));
Console.Write("Generating {0} KB testfile . . .\n", testfileSizeKb);
var fs = new FileStream(testfileRaw, FileMode.CreateNew);
fs.Seek(testfileSizeKb*1024, SeekOrigin.Begin);
fs.WriteByte(0);
fs.Close();
Console.Write("Encrypting testfile . . .\n");
var encryptedFile = await Cryptor.EncryptFileWithStreamAsync(keyPair, testfileRaw, progressEncrypt);
Console.Write("Decrypting testfile . . .\n");
await
Cryptor.DecryptFileWithStreamAsync(keyPair,
Path.Combine(TestContext.CurrentContext.TestDirectory, outputDirectory, encryptedFile),
testfileDecryptedOutputDirectory, progressDecrypt);
Console.Write("Get checksum of testfiles . . .\n");
Assert.AreEqual(Utils.GetChecksum(testfileRaw), Utils.GetChecksum(testfileDecryptedFile));
//clear garbage
File.Delete(testfileRaw);
File.Delete(Path.Combine(TestContext.CurrentContext.TestDirectory, outputDirectory, encryptedFile));
File.Delete(testfileDecryptedFile);
}