示例#1
0
        private void decryptFilesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var list = FileManager.OpenFile(ofd, "Select files to decrypt", true);

            if (list == null)
            {
                return;
            }

            var outDir = FileManager.SaveFile(ffd);

            if (outDir == null)
            {
                return;
            }

            var key = GetKey();

            if (string.IsNullOrEmpty(key))
            {
                return;
            }

            foreach (var l in ClassAcm.DecryptFileList(list, outDir, key))
            {
                WriteLogs(l + "\r\n");
            }
        }
示例#2
0
        public void TestACMDecryptFileList()
        {
            var dir      = ConfigurationManager.AppSettings.Get("test_dir");
            var key      = ConfigurationManager.AppSettings.Get("secret_key");
            var testList = GenerateAcmFilesList().ToList();
            var sol      = new List <string>()
            {
                "File successfully decrypted: " + dir + "/" + Path.GetFileNameWithoutExtension(testList.ElementAt(0)) +
                "_dec.txt",
                "File successfully decrypted: " + dir + "/" + Path.GetFileNameWithoutExtension(testList.ElementAt(1)) +
                "_dec.txt",
                "File successfully decrypted: " + dir + "/" + Path.GetFileNameWithoutExtension(testList.ElementAt(2)) +
                "_dec.txt"
            };

            //OK
            CollectionAssert.AreEqual(ClassAcm.DecryptFileList(testList, dir, key).ToList(), sol);
            //Exceptions//Exceptions
            Assert.AreEqual(ClassAcm.DecryptFileList(new List <string>()
            {
                "./umpalumpa.txt"
            }, dir, key).ToList().ElementAt(0), "Exception on decryption: File not found");
            Assert.AreEqual(ClassAcm.DecryptFileList(testList, "./umpalumpa", key).ToList().ElementAt(0), "Exception on decryption: Directory not found");
            Assert.AreEqual(ClassAcm.DecryptFileList(testList, dir, "").ToList().ElementAt(0), "Exception on decryption: Null key");
            File.Create(Path.ChangeExtension(testList.ElementAt(0), ".docx")).Close();
            Assert.AreEqual(ClassAcm.DecryptFileList(new List <string>()
            {
                Path.ChangeExtension(testList.ElementAt(0), ".docx")
            }, dir, key).ToList().ElementAt(0), "Exception on decryption: Wrong file format. This function can decrypt only .acm files");
            File.Create(dir + "/empty.acm").Close();
            Assert.AreEqual(ClassAcm.DecryptFileList(new List <string>()
            {
                dir + "/empty.acm"
            }, dir, key).ToList().ElementAt(0), "Exception on decryption: Empty file");
            File.WriteAllText(testList.ElementAt(0), File.ReadAllText(testList.ElementAt(0)).Replace("Hash=", "Hash=r"));
            Assert.AreEqual(ClassAcm.DecryptFileList(testList, dir, key).ToList().ElementAt(0), "Exception on decryption: MD5 hash functions not corresponding");
        }