Exemplo n.º 1
0
        private void bt_decrypt_Click(object sender, RoutedEventArgs e)
        {
            if (!this.freeEvent.WaitOne(0))
            {
                MessageBox.Show(Properties.Resources.Backend_Busy);
                return;
            }

            string    rsaKey        = this.privateKey;
            string    encryptedFile = this.tb_encryptedFilePath.Text;
            string    plainFile     = MakePath(encryptedFile, ".decrypted");
            string    manifestFile  = this.manifestFilePath;
            XDocument doc           = XDocument.Load(manifestFile);
            XElement  aesKeyElement = doc.Root.XPathSelectElement("./DataEncryption/AESEncryptedKeyValue/Key");

            byte[]   aesKey       = Encipher.RSADescryptBytes(Convert.FromBase64String(aesKeyElement.Value), rsaKey);
            XElement aesIvElement = doc.Root.XPathSelectElement("./DataEncryption/AESEncryptedKeyValue/IV");

            byte[] aesIv = Encipher.RSADescryptBytes(Convert.FromBase64String(aesIvElement.Value), rsaKey);

            this.tb_outputDecrypt.Text = Properties.Resources.Out_msg_start_decryption;
            var t = Task.Factory.StartNew(() =>
            {
                freeEvent.Reset();
                Encipher.DecryptFile(plainFile, encryptedFile, aesKey, aesIv);
                freeEvent.Set();
                //this.UpdateOutput(this.tb_outputDecrypt, string.Format(Properties.Resources.Out_msg_decryption_success, plainFile), true);
            });
        }
Exemplo n.º 2
0
        private void bt_encrypt_Click(object sender, RoutedEventArgs e)
        {
            if (!this.freeEvent.WaitOne(0))
            {
                MessageBox.Show(Properties.Resources.Backend_Busy);
                return;
            }

            if (string.IsNullOrEmpty(publicKey))
            {
                MessageBox.Show(this, Properties.Resources.Error_Need_PublicKey);
                return;
            }

            string plainFilePath     = this.tb_plainFilePath.Text;
            string encryptedFilePath = MakePath(plainFilePath, ".encrypted");
            string manifestFilePath  = MakePath(plainFilePath, ".manifest.xml");

            this.tb_output.Text = Properties.Resources.Out_msg_start_encryption;

            var t = Task.Factory.StartNew(() =>
            {
                freeEvent.Reset();
                string s = Encipher.Encrypt(plainFilePath,
                                            encryptedFilePath,
                                            manifestFilePath,
                                            this.publicKey);

                freeEvent.Set();
                this.UpdateOutput(this.tb_output, Properties.Resources.Out_msg_encrypt_success + "\r\n" + s, true);
            });
        }
Exemplo n.º 3
0
        private void mi_genKeyPair_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog fbd = new SaveFileDialog();

            fbd.FileName = "publicKey.xml";
            Nullable <bool> result = fbd.ShowDialog();

            if (result == true)
            {
                Encipher.GenerateRSAKeyPair(out publicKey, out privateKey);
                using (StreamWriter sw = File.CreateText(fbd.FileName))
                {
                    sw.Write(publicKey);
                }
            }

            SaveFileDialog dlg = new SaveFileDialog();

            dlg.FileName = "privateKey.xml";
            Nullable <bool> resultTwo = dlg.ShowDialog();

            if (result == true)
            {
                using (StreamWriter sw = File.CreateText(dlg.FileName))
                {
                    sw.Write(privateKey);
                }
            }
        }
Exemplo n.º 4
0
        private static void GenerateRSAKeyPair()
        {
            string publicKey  = string.Empty;
            string privateKey = string.Empty;

            Encipher.GenerateRSAKeyPair(out publicKey, out privateKey);
        }
Exemplo n.º 5
0
 public Session(uint uint_3, Socket Socket)
 {
     this.uint_0            = uint_3;
     this.socket_0          = Socket;
     this.byte_0            = new byte[0x400];
     this.encipher_0        = new Encipher();
     this.bool_0            = true;
     this.socket_0.Blocking = false;
     Output.WriteLine("Started client #" + uint_3 + ".", OutputLevel.DebugInformation);
     this.method_0();
 }