public void TestCreateFromKeyFile() { string password = "******"; string wrongpassword = password + "wrong"; AesHelper aesHelper = AesHelper.CreateFromPassword(password); byte[] keyfile = aesHelper.CreateKeyFile(); // Test wrong password AesHelper aesHelper2; Assert.ThrowsException <AesHelper.PasswordIncorrectException>( () => AesHelper.CreateFromKeyFile(keyfile, wrongpassword)); // Test correct password aesHelper2 = AesHelper.CreateFromKeyFile(keyfile, password); Assert.IsNotNull(aesHelper2); // NOTE: Do not test equivalent encryption, IV is random // so multiple encryptions will return different files // Test Equivalent decryption byte[] data = new byte[100]; CoreTest.RandomData(data); byte[] decrypted = aesHelper.DecryptBytes(aesHelper.EncryptBytes(data)); Assert.IsTrue(decrypted.SequenceEqual(data)); Assert.IsTrue(decrypted .SequenceEqual(aesHelper2.DecryptBytes(aesHelper2.EncryptBytes(data)))); byte[] decrypted2 = aesHelper2.DecryptBytes(aesHelper.EncryptBytes(data)); decrypted2.SequenceEqual(data); Assert.IsTrue(decrypted2 .SequenceEqual(aesHelper.DecryptBytes(aesHelper2.EncryptBytes(data)))); }
public void TestDecrypt() { AesHelper aesHelper = AesHelper.CreateFromPassword("12"); byte[] data = new byte[0]; byte[] encrypted = aesHelper.EncryptBytes(data); byte[] decrypted = aesHelper.DecryptBytes(encrypted); Assert.IsNotNull(decrypted); Assert.IsTrue(encrypted.Length == decrypted.Length); Assert.IsTrue(data.SequenceEqual(decrypted)); data = new byte[1]; CoreTest.RandomData(data); encrypted = aesHelper.EncryptBytes(data); decrypted = aesHelper.DecryptBytes(encrypted); Assert.IsNotNull(decrypted); Assert.IsTrue(encrypted.Length > decrypted.Length); Assert.IsTrue(data.SequenceEqual(decrypted)); data = new byte[1000]; CoreTest.RandomData(data); encrypted = aesHelper.EncryptBytes(data); decrypted = aesHelper.DecryptBytes(encrypted); Assert.IsNotNull(decrypted); Assert.IsTrue(encrypted.Length > decrypted.Length); Assert.IsTrue(data.SequenceEqual(decrypted)); }
static void Main(string[] args) { //BPlusTreeTest bpt_test = new BPlusTreeTest(); //bpt_test.TestSerializeDeserialize(); //GetStatus("test", @"C:\Users\Wesley\Desktop\test\src", @"C:\Users\Wesley\Desktop\test\dst"); //BackupRun("test", @"C:\Users\Wesley\Desktop\test\src", @"C:\Users\Wesley\Desktop\test\dst"); //BinaryEncodingTest betest = new BinaryEncodingTest(); //betest.TestDictEncodeDecode(); //betest.TestEnumEncodeDecode(); //BlobStoreTest bstest = new BlobStoreTest(); //bstest.TestSplitData(); //bstest.TestBlobStoreDeserialize(); CoreTest.CoreTest ctest = new CoreTest.CoreTest(); //ctest.TestCheckTrackFile(); //ctest.TestCheckTrackAnyDirectoryChild(); //ctest.TestInitializeNew(); //ctest.TestRunBackup(); //ctest.TestRestore(); ctest.TestRemoveBackup(); //ctest.TestInitializeNew(); //ctest.TestLoadCore_NewlyInitialized(); //BPlusTreeTest bptt = new BPlusTreeTest(); //bptt.TestAddRemove(); //bptt.TestAddMany(); //bptt.TestAddRemoveMany(); //HashToolsTest htt = new HashToolsTest(); //htt.TestByteArrayLessThan(); //MakeManyFiles(1000, 1000000, @"D:\src"); //Console.WriteLine(TimeSimpleCopy(@"D:\src", @"D:\dst")); //Console.WriteLine(BackupRun("test", @"D:\src", @"D:\dst")); //GetStatus("test", @"C:\Users\Wesley\Desktop\test\src", @"C:\Users\Wesley\Desktop\test\dst"); //var bbi = new BackupCore.BackblazeInterop(); //(var hash, var data) = MakeRandomFile(30); //Console.WriteLine(bbi.FileExists("hashindex").Result); //Console.WriteLine(bbi.DownloadFile("hashindex").Result.Length); //Console.ReadLine(); /* * BackupCore.FSCoreSrcDependencies srcdeps = BackupCore.FSCoreSrcDependencies.Load(@"C:\Users\Wesley\Desktop\test\src", new BackupCore.DiskFSInterop()); * BackupCore.BackblazeCoreDstDependencies bbdestdeps = BackupCore.BackblazeCoreDstDependencies.Load(new BackupCore.BackblazeInterop("BBConnection.json"), false); * BackupCore.Core core = new BackupCore.Core(srcdeps, bbdestdeps); * core.RunBackup("test", "try"); * Console.ReadLine(); * Console.WriteLine(core.GetBackups("test").backups.First().message); * Console.ReadLine(); */ }
public void TestAesHelperReconstruct() { string password = "******"; AesHelper aesHelper = AesHelper.CreateFromPassword(password); byte[] keyfile = aesHelper.CreateKeyFile(); // Test correct password AesHelper aesHelperDirect = new AesHelper(aesHelper.DataKeyKey, aesHelper.PasswordSalt, aesHelper.DataKeyKeyHash, aesHelper.DataKeyKeyHashSalt, aesHelper.DataKeyAesProvider, aesHelper.DataKeyIV, aesHelper.DataKey); Assert.IsNotNull(aesHelperDirect); Assert.IsTrue(aesHelper.DataKeyKey.SequenceEqual(aesHelper.DataKeyAesProvider.Key)); Assert.IsTrue(aesHelper.DataKeyIV.SequenceEqual(aesHelper.DataKeyAesProvider.IV)); RijndaelManaged dataKeyAesProvider = AesHelper.CreateDataKeyAesProvider(aesHelper.DataKeyKey); dataKeyAesProvider.IV = aesHelper.DataKeyIV; byte[] decryptedAesDataKey = AesHelper.DecryptAesDataKey(aesHelper.EncryptAesDataKey(), dataKeyAesProvider); Assert.IsTrue(decryptedAesDataKey.SequenceEqual(aesHelper.DataKey)); //AesHelper aesHelperFromFile = AesHelper.CreateFromKeyFile(keyfile, password); AesHelper aesHelperFromFile = AesHelper.CreateFromKeyFile(aesHelper.PasswordSalt, aesHelper.DataKeyKeyHashSalt, aesHelper.DataKeyIV, aesHelper.DataKeyKeyHash, aesHelper.EncryptAesDataKey(), password); Assert.IsTrue(aesHelperDirect.DataKeyKey.SequenceEqual(aesHelperFromFile.DataKeyKey)); Assert.IsTrue(aesHelperDirect.PasswordSalt.SequenceEqual(aesHelperFromFile.PasswordSalt)); Assert.IsTrue(aesHelperDirect.DataKeyKeyHash.SequenceEqual(aesHelperFromFile.DataKeyKeyHash)); Assert.IsTrue(aesHelperDirect.DataKeyKeyHashSalt.SequenceEqual(aesHelperFromFile.DataKeyKeyHashSalt)); Assert.IsTrue(aesHelperDirect.DataKeyIV.SequenceEqual(aesHelperFromFile.DataKeyIV)); Assert.IsTrue(aesHelperDirect.DataKey.SequenceEqual(aesHelperFromFile.DataKey)); // NOTE: Do not test equivalent encryption, IV is random // so multiple encryptions will return different files // Test Equivalent decryption byte[] data = new byte[100]; CoreTest.RandomData(data); byte[] decrypted = aesHelper.DecryptBytes(aesHelper.EncryptBytes(data)); Assert.IsTrue(decrypted.SequenceEqual(data)); Assert.IsTrue(decrypted .SequenceEqual(aesHelperDirect.DecryptBytes(aesHelperDirect.EncryptBytes(data)))); byte[] decrypted2 = aesHelperDirect.DecryptBytes(aesHelper.EncryptBytes(data)); decrypted2.SequenceEqual(data); Assert.IsTrue(decrypted2 .SequenceEqual(aesHelper.DecryptBytes(aesHelperDirect.EncryptBytes(data)))); }
public void TestGetFile() { MetadataNode mtree = CoreTest.CreateBasicVirtualFS(1); var a = VirtualFSInterop.MakeNewFileMetadata("a.ext", 100); mtree.AddFile(a); var b = VirtualFSInterop.MakeNewFileMetadata("b"); mtree.AddFile("src", b); mtree.AddDirectory("dst", VirtualFSInterop.MakeNewDirectoryMetadata("hat")); var c = VirtualFSInterop.MakeNewFileMetadata("c.ext"); mtree.AddFile(Path.Combine("dst", "hat"), c); Assert.AreSame(mtree.GetFile("a.ext"), a); Assert.AreSame(mtree.GetFile(Path.Combine("src", "b")), b); Assert.AreSame(mtree.GetFile(Path.Combine("dst", "hat", "c.ext")), c); }
public void TestSplitData() { // We test by first making 8 total random blocks of data a-h // The Data are arranged as follows // [ small block_a ] = 2 KB // [ large block_b ] = 2 MB // [ small block_c ] = 8 bytes // [ large block_d ] = 4 MB // [ small block_e ] = 4 KB // These are then concenated then split by BS.SplitData() // Small blocks a and e are exchanged for equally sized random blocks f, h // Small block c is replaced with g, a block of size 1 // Concenated and split again // Make sure when hashes match data is same length // Verify size of data represented by "new" hashes is < 20 MB byte[] small_a = new byte[2048]; CoreTest.RandomData(small_a); byte[] large_b = new byte[2_971_520];