/// <summary> /// Test the VolumeCipher class implementation /// </summary> public static void VolumeCipherTest(string InputDirectory) { string[] paths = DirectoryTools.GetFiles(InputDirectory); // set cipher paramaters CipherDescription desc = new CipherDescription( SymmetricEngines.RDX, 32, IVSizes.V128, CipherModes.CTR, PaddingModes.X923, BlockSizes.B128, RoundCounts.R14, Digests.Keccak512, 64, Digests.Keccak512); // define the volume key VolumeKey vkey = new VolumeKey(desc, paths.Length); // key will be written to this stream MemoryStream keyStream = new MemoryStream(); // create the volume key stream using (VolumeFactory vf = new VolumeFactory(keyStream)) vf.Create(vkey); // encrypt the files in the directory using (VolumeCipher vc = new VolumeCipher(true, keyStream)) vc.Transform(paths); // decrypt the files using (VolumeCipher vc = new VolumeCipher(false, keyStream)) vc.Transform(paths); // manual inspection of files.. }
/// <summary> /// Creates a temporary VolumeKey on disk, extracts and compares the copy /// <para>Throws an Exception on failure</</para> /// </summary> public static void VolumeFactoryTest() { string path = GetTempPath(); // cipher paramaters CipherDescription desc = new CipherDescription( SymmetricEngines.RDX, 32, IVSizes.V128, CipherModes.CTR, PaddingModes.X923, BlockSizes.B128, RoundCounts.R14, Digests.Keccak512, 64, Digests.Keccak512); // create the package key VolumeKey vkey = new VolumeKey(desc, 10); // add id's for (int i = 0; i < vkey.FileId.Length; i++) vkey.FileId[i] = i; // write a key file using (VolumeFactory vf = new VolumeFactory(path)) vf.Create(vkey); for (int i = 0; i < vkey.Count; i++) { CipherDescription desc2; KeyParams kp1; KeyParams kp2; using (FileStream stream = new FileStream(path, FileMode.Open)) kp1 = VolumeKey.AtIndex(stream, i); int id = vkey.FileId[i]; // read the package using (VolumeFactory vf = new VolumeFactory(path)) vf.Extract(id, out desc2, out kp2); // compare key material if (!Compare.AreEqual(kp1.Key, kp2.Key)) throw new Exception(); if (!Compare.AreEqual(kp1.IV, kp2.IV)) throw new Exception(); if (!desc.Equals(desc2)) throw new Exception(); } if (File.Exists(path)) File.Delete(path); }