Example #1
0
        private void encryptFilesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var list = FileManager.OpenFile(ofd, "Select files to encrypt", 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.EncryptFileList(list, outDir, key))
            {
                WriteLogs(l + "\r\n");
            }
        }
Example #2
0
        public void TestACMEncryptFileListOk()
        {
            var dir      = ConfigurationManager.AppSettings.Get("test_dir");
            var key      = ConfigurationManager.AppSettings.Get("secret_key");
            var md5_1    = ConfigurationManager.AppSettings.Get("txt_file_md5_1").ToUpper();
            var md5_2    = ConfigurationManager.AppSettings.Get("txt_file_md5_2").ToUpper();
            var md5_3    = ConfigurationManager.AppSettings.Get("txt_file_md5_3").ToUpper();
            var testList = GenerateTxtFilesList().ToList();
            var file1    = Path.ChangeExtension(testList.ElementAt(0), "acm");
            var file2    = Path.ChangeExtension(testList.ElementAt(1), "acm");
            var file3    = Path.ChangeExtension(testList.ElementAt(2), "acm");

            //OK return
            var sol = new List <string>()
            {
                $"File successfully encrypted: {file1}\r\nMD5 = {md5_1}",
                $"File successfully encrypted: {file2}\r\nMD5 = {md5_2}",
                $"File successfully encrypted: {file3}\r\nMD5 = {md5_3}",
            };

            //OK
            CollectionAssert.AreEqual(ClassAcm.EncryptFileList(testList, dir, key).ToList(), sol);
            //Exceptions
            Assert.AreEqual(ClassAcm.EncryptFileList(new List <string>()
            {
                "./umpalumpa.txt"
            }, outDir: dir, key: key).ToList().ElementAt(0), "Exception on encryption: File not found");
            Assert.AreEqual(ClassAcm.EncryptFileList(testList, "./umpalumpa", key).ToList().ElementAt(0), "Exception on encryption: Directory not found");
            Assert.AreEqual(ClassAcm.EncryptFileList(testList, dir, "").ToList().ElementAt(0), "Exception on encryption: Null key");
            File.Create(Path.ChangeExtension(testList.ElementAt(0), ".docx")).Close();
            Assert.AreEqual(ClassAcm.EncryptFileList(new List <string>()
            {
                Path.ChangeExtension(testList.ElementAt(0), ".docx")
            }, dir, key).ToList().ElementAt(0), "Exception on encryption: Wrong file format. This function can encrypt only .txt files");
            File.Create(dir + "/empty.txt").Close();
            Assert.AreEqual(ClassAcm.EncryptFileList(new List <string>()
            {
                dir + "/empty.txt"
            }, dir, key).ToList().ElementAt(0), "Exception on encryption: Empty file");
        }