Exemplo n.º 1
0
        public void Encrypt(string path)
        {
            string keyPath = KeyStorage.Instance().GetKeyPath();

            Console.WriteLine($"Encrypting the file using {keyPath} key");

            using (var rsa = new RSACryptoServiceProvider())
            {
                try
                {
                    rsa.FromXmlString(File.ReadAllText(keyPath));
                    byte[] bytesToEncrypt = File.ReadAllBytes(path);
                    byte[] encrypted      = rsa.Encrypt(bytesToEncrypt, false);

                    var pureFileName = Path.GetFileName(path).Split('.')[0];
                    File.WriteAllBytes($"{pureFileName}_ENCRYPTED.txt", encrypted);

                    Process.Start("explorer.exe", Directory.GetCurrentDirectory());
                }
                catch (Exception exception)
                {
                    MessageBox.Show("Nieprawidłowy klucz!");
                }
            }
        }
Exemplo n.º 2
0
        public void Decrypt()
        {
            string keyPath = KeyStorage.Instance().GetKeyPath();

            Console.WriteLine($"Decrypting the file using {keyPath} key");

            using (var rsa = new RSACryptoServiceProvider())
            {
                rsa.FromXmlString(File.ReadAllText(keyPath));
                byte[] bytesToDecrypt = File.ReadAllBytes(filePath);
                try
                {
                    byte[] decrypted       = rsa.Decrypt(bytesToDecrypt, false);
                    var    decryptedString = Encoding.UTF8.GetString(decrypted);
                    var    pureFileName    = Path.GetFileName(filePath).Split('.')[0].Split('_')[0];
                    var    extension       = Path.GetFileName(filePath).Split('.')[1];
                    File.WriteAllText($"{pureFileName}_DECRYPTED.{extension}", decryptedString);
                    Process.Start("explorer.exe", Directory.GetCurrentDirectory());
                }
                catch (Exception exception)
                {
                    MessageBox.Show("Nieprawidłowy klucz!");
                }
            }
        }
Exemplo n.º 3
0
        private void CopyButton_OnClick(object sender, RoutedEventArgs e)
        {
            var keyPath = KeyStorage.Instance().GetKeyPath();

            Clipboard.SetText(File.ReadAllText(keyPath));
            Close();
        }
Exemplo n.º 4
0
        private void RefreshAvailableKeys()
        {
            KeysListBox.Items.Clear();
            foreach (var keyFileName in KeyStorage.GetKeysInDirectory())
            {
                var item          = new ListBoxItem();
                var displayedName = "";
                var pureName      = keyFileName.Split('.')[0].Split('_')[0];
                var fileSufix     = keyFileName.Split('.')[0].Split('_')[1];

                displayedName += pureName;

                if (fileSufix == "PRIVATE")
                {
                    displayedName = "🔒 " + displayedName;
                }
                else
                {
                    displayedName = "     " + displayedName;
                }

                item.Selected         += KeyStorage.Instance().ChooseKey;
                item.Selected         += ChangeButtonsState;
                item.MouseDoubleClick += DisplayKeyInfo;
                item.Content           = displayedName;
                item.Tag = keyFileName;
                KeysListBox.Items.Add(item);
            }
        }
Exemplo n.º 5
0
        private void InitializeData()
        {
            var keyPath = KeyStorage.Instance().GetKeyPath();

            KeyNameText.Text = "Nazwa: " + Path.GetFileName(keyPath);

            KeyCreationDateText.Text = "Stworzono: " + new FileInfo(keyPath).CreationTime.ToString();

            var rsa = new RSACryptoServiceProvider();

            rsa.FromXmlString(File.ReadAllText(keyPath));
            KeySizeText.Text = "Rozmiar: " + rsa.KeySize.ToString();
        }