示例#1
0
 private static void DecryptFile(string serialFile, out string message, out string version, out string outputFile)
 {
     outputFile = "version.xml";
     message    = string.Empty;
     version    = string.Empty;
     FileCipher.DecryptFile(serialFile, outputFile, out message);
 }
示例#2
0
        private async void ExportBtn_Click(object sender, EventArgs e)
        {
            if (Selection().Count == 0)
            {
                return;
            }

            FolderBrowserDialog a = new FolderBrowserDialog();

            a.ShowDialog();
            progressBar1.Maximum = Selection().Count;
            foreach (var item in Selection())
            {
                try
                {
                    progressBar1.Invoke((MethodInvoker) delegate
                    {
                        progressBar1.Value++;
                    });
                    var dist  = Path.Combine(a.SelectedPath, Path.GetFileName(item.vid.Source));
                    var bytes = await FileCipher.StreamFromEncdFile(item.vid.CodedFilePath);

                    File.WriteAllBytes(dist, bytes.ToArray());
                }catch (Exception q) { Debug.WriteLine(q.Message); }
            }
            progressBar1.Value = 0;
        }
示例#3
0
        public static void GenerateSerialFile(string runtimeMode, string serialNo)
        {
            XmlDocument doc     = new XmlDocument();
            XmlNode     docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);

            doc.AppendChild(docNode);

            XmlNode productsNode = doc.CreateElement("products");

            doc.AppendChild(productsNode);

            XmlNode      productNode      = doc.CreateElement("product");
            XmlAttribute productAttribute = doc.CreateAttribute("id");

            productAttribute.Value = "2017";
            productNode.Attributes.Append(productAttribute);
            productsNode.AppendChild(productNode);

            XmlNode nameNode = doc.CreateElement("Name");

            nameNode.AppendChild(doc.CreateTextNode("Pajak Online Kota Surabaya"));
            productsNode.AppendChild(nameNode);
            XmlNode priceNode = doc.CreateElement("RuntimeMode");

            priceNode.AppendChild(doc.CreateTextNode(runtimeMode));
            ClassHelper.RuntimeMode = runtimeMode;
            productsNode.AppendChild(priceNode);

            XmlNode versionNode = doc.CreateElement("Version");

            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            FileVersionInfo            fvi      = FileVersionInfo.GetVersionInfo(assembly.Location);
            string version = fvi.FileVersion;

            versionNode.AppendChild(doc.CreateTextNode(version)); // get version from executing assembly version
            productNode.AppendChild(versionNode);

            XmlNode serialNumber = doc.CreateElement("SerialNumber");

            //serialNumber.AppendChild(doc.CreateTextNode("0000-0000-0000-0000-0000"));
            serialNumber.AppendChild(doc.CreateTextNode(serialNo));
            productsNode.AppendChild(serialNumber);
            string inputFile = "serial.xml";

            doc.Save(inputFile);

            string message = string.Empty;

            FileCipher.EncryptFile(inputFile, SerialFile, out message);
            FileInfo file = new FileInfo(inputFile);

            file.Delete();
        }
        private void ButtonDecryptClick(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(currentWorkingFile))
            {
                ConfigureSymmetricAlgorithm configurator = new ConfigureSymmetricAlgorithm(
                    Crypter.Enums.SymmetricAlgorithm.AES,
                    CipherMode.CBC,
                    PaddingMode.ISO10126,
                    128,
                    256);

                FileCipher.DecryptFileWrapper(currentWorkingFile, currentWorkingFile
                                              .CreateNameByPredictName("Decrypted"), configurator, password);

                MessageBox.Show("Decrypt done.");
            }
        }
        public static IEnumerable <PerfomanceInfoView> FullEncryptionCycleForDirectory(IEnumerable <string> fileNames)
        {
            Stopwatch stopwatch = new Stopwatch();

            ConfigureSymmetricAlgorithm configurator = new ConfigureSymmetricAlgorithm(
                SymmetricAlgorithm.AES,
                CipherMode.CBC,
                PaddingMode.ISO10126,
                128,
                256);

            foreach (var file in fileNames)
            {
                var encryptFileName = file.CreateNameByPredictName("Encrypted");
                var decryptFileName = file.CreateNameByPredictName("Decrypted");

                stopwatch.Restart();
                string key = NormalityDistributionKey.GeneratedPassword();
                stopwatch.Stop();
                var keyTime = stopwatch.ElapsedMilliseconds;

                stopwatch.Restart();
                FileCipher.EncryptFileWrapper(file, encryptFileName, configurator, key);
                stopwatch.Stop();
                var encryptTime = stopwatch.ElapsedMilliseconds;

                stopwatch.Restart();
                FileCipher.DecryptFileWrapper(encryptFileName, decryptFileName, configurator, key);
                stopwatch.Stop();
                var decryptTime = stopwatch.ElapsedMilliseconds;


                yield return(new PerfomanceInfoView(
                                 file,
                                 keyTime,
                                 encryptTime,
                                 decryptTime,
                                 new System.IO.FileInfo(file).Length,
                                 new System.IO.FileInfo(encryptFileName).Length));
            }
        }
示例#6
0
 private async void PlayBtn_Click(object sender, EventArgs e)
 {
     MainForm.Frm.videoViewer2.FromStream(await FileCipher.StreamFromEncdFile((this).vid.CodedFilePath));
 }
示例#7
0
        private void saveFileDialog_FileOk(object sender, CancelEventArgs e)
        {
            var path = saveFileDialog.FileName;

            if (!File.Exists(txtSource.Text))
            {
                MessageBox.Show("Please select a valid source.", "File not found !",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (!File.Exists(path))
            {
                MessageBox.Show("Please select a valid destination.", "File not found !",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            UInt32 seed = 0;

            if (!UInt32.TryParse(txtKey.Text, out seed))
            {
                MessageBox.Show("Please specify a valid key for the cipher.", "Invalid key !",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            var cipher = new FileCipher(seed);

            byte[] buffer = new byte[4096];
            int    read   = 0;

            bool encrypt = rbtnEncrypt.Checked;

            try
            {
                using (var input = new FileStream(txtSource.Text, FileMode.Open, FileAccess.Read))
                {
                    using (var output = new FileStream(path, FileMode.Create, FileAccess.Write))
                    {
                        read = input.Read(buffer, 0, buffer.Length);
                        while (read > 0)
                        {
                            if (encrypt)
                            {
                                cipher.Encrypt(ref buffer, read);
                            }
                            else
                            {
                                cipher.Decrypt(ref buffer, read);
                            }

                            output.Write(buffer, 0, read);
                            read = input.Read(buffer, 0, buffer.Length);
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                var type = exc.GetType().ToString();
                var msg  = exc.Message;

                MessageBox.Show(
                    String.Format("Something wrong happened while saving the encrypted/decrypted file.\n{0}: {1}", type, msg), "Error !",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#8
0
        public static bool CheckLatestVersion(out string pesan)
        {
            pesan = string.Empty;
            bool isLatestVersion = false;

            System.Reflection.Assembly ass = System.Reflection.Assembly.GetExecutingAssembly();
            FileVersionInfo            fvi = FileVersionInfo.GetVersionInfo(ass.Location);
            string assemblyVersion         = fvi.FileVersion;
            string pofVersion    = string.Empty;
            string latestVersion = string.Empty;
            string serialFile    = "POFtpSender.pof";
            string message       = string.Empty;
            string version       = string.Empty;

            GetPofVersion(serialFile, out message, out version);
            pofVersion = version;
            if (string.Compare(pofVersion, assemblyVersion) != 0)
            {
                string outputFile;
                DecryptFile(serialFile, out message, out version, out outputFile);

                FileInfo info = new FileInfo(outputFile);
                if (info.Exists)
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(outputFile); //Assuming reader is your XmlReader

                    XmlNode nodeversion = doc.SelectSingleNode("products/Version");
                    if (nodeversion == null)
                    {
                        XmlNode root = doc.DocumentElement;

                        XmlElement elem = doc.CreateElement("Version");
                        elem.InnerText = assemblyVersion;
                        root.AppendChild(elem);
                    }
                    else
                    {
                        nodeversion.InnerXml = assemblyVersion;
                    }

                    //XmlNode node = doc.SelectSingleNode("products/product").LastChild;
                    //node.InnerXml = assemblyVersion;
                    doc.Save(outputFile);
                    FileCipher.EncryptFile(outputFile, serialFile, out message);
                    info.Delete();
                    pofVersion = assemblyVersion;
                }
            }

            string newVersion = DbLatestVersion();

            if (string.IsNullOrEmpty(newVersion))
            {
                pesan           = "Gagal mendapatkan versi terbaru server";
                isLatestVersion = true;
            }
            else
            {
                if (string.Compare(assemblyVersion.Replace(" ", string.Empty), newVersion.Replace(" ", string.Empty)) == 0)
                {
                    isLatestVersion = true;
                }
            }

            return(isLatestVersion);
        }