Exemplo n.º 1
0
        public void EncryptDecryptFile_ShouldWork()
        {
            var bytes = Symetric.GetRandomBytes(1024 * 1024 * 8);

            var fileInfo = new FileInfo("testfile.fi");

            File.WriteAllBytes(fileInfo.FullName, bytes);

            fileInfo.EncryptFileInPlace("passs", KeySize.Highest_256);
            fileInfo.DecryptFileInPlace("passs");

            var fromFile = File.ReadAllBytes(fileInfo.FullName);

            fileInfo.Delete();

            bytes.Should().BeEquivalentTo(fromFile);
        }
Exemplo n.º 2
0
        public void EncryptDecryptLargeFile_ShouldWork()
        {
            var fileInfo = new FileInfo("largetestfile.fi");

            using (var ws = fileInfo.OpenWrite())
            {
                for (int i = 0; i < 1024 * 3; i++) //3Gb --> 1Mb per round
                {
                    ws.Write(Symetric.GetRandomBytes(1024 * 1024 * 8));
                }
            }

            var crypted   = fileInfo.EncryptFile("passs", false, KeySize.Highest_256);
            var decrypted = crypted.DecryptFile("passs", true);


            var result = fileInfo.Base64HashFromFile() == decrypted.Base64HashFromFile();

            fileInfo.Delete();
            decrypted.Delete();
            result.Should().BeTrue();
        }