Beispiel #1
0
        public void TestEncryptFile()
        {
            var encryptor = new TripleDes();
            string file = FILE1, encrypted = FILE1 + ".3des_encrypted", decrypted = FILE1 + ".3des_decrypted",
                key = "password", salt = "this_is_salt";

            // without salt
            encryptor.EncryptFile(file, encrypted, key);
            Assert.True(File.Exists(encrypted));
            encryptor.DecryptFile(encrypted, decrypted, key);
            Assert.True(File.Exists(decrypted));
            Assert.Equal(new FileInfo(file).ReadBytes().ToHexaDecimalString(), new FileInfo(decrypted).ReadBytes().ToHexaDecimalString());

            // with salt
            encryptor.EncryptFile(file, encrypted, key, salt);
            Assert.True(File.Exists(encrypted));
            encryptor.DecryptFile(encrypted, decrypted, key);
            Assert.True(File.Exists(decrypted));
            Assert.Equal(new FileInfo(file).ReadBytes().ToHexaDecimalString(), new FileInfo(decrypted).ReadBytes().ToHexaDecimalString());
        }