Пример #1
0
 private void encryptButton_Click(object sender, EventArgs e)
 {
     try
     {
         if (IsSignatureMode())
         {
             Signer s = GetSigner();
             if (s != null)
             {
                 outputText.Text            = s.sign(inputText.Text, signKey).ToString();
                 lblIntermediateValues.Text = s.SignIntermediateValues;
             }
         }
         else
         {
             EncryptionStrategy s = GetEncryptionStrategy();
             if (s != null)
             {
                 outputText.Text = s.encrypt();
             }
         }
     }
     catch (Exception err)
     {
         MessageBox.Show(err.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Пример #2
0
 private void decryptButton_Click(object sender, EventArgs e)
 {
     try
     {
         if (IsSignatureMode())
         {
             Signer s = GetSigner(Mode.CheckSignature);
             if (s != null)
             {
                 if (s.checkSignature(new DSASignedString(inputText.Text), signKey))
                 {
                     System.Windows.Forms.MessageBox.Show("Подпись верна");
                 }
                 else
                 {
                     System.Windows.Forms.MessageBox.Show("Подпись НЕ верна");
                 }
                 lblIntermediateValues.Text = s.CheckSignatureIntermediateValues;
             }
         }
         else
         {
             EncryptionStrategy s = GetEncryptionStrategy(Mode.Decrypt);
             if (s != null)
             {
                 outputText.Text = s.decrypt();
             }
         }
     }
     catch (Exception err)
     {
         MessageBox.Show(err.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Пример #3
0
        public EncryptedWorkspaceTests()
        {
            _workspace         = new Workspace("Name", "Description");
            _workspace.Version = "1.2.3";
            _workspace.Id      = 1234;
            _workspace.Configuration.AddUser("*****@*****.**", Role.ReadOnly);

            _encryptionStrategy = new MockEncryptionStrategy();
        }
Пример #4
0
        private EncryptionStrategy GetEncryptionStrategy(Mode mode = Mode.Encrypt)
        {
            EncryptionStrategy result = null;
            String             input  = inputText.Text;

            switch (algorithmDrowdown.Text)
            {
            case "Железнодорожная изгородь":
                try
                {
                    int key = int.Parse(keyInput.Text);
                    result = new EncryptionStrategies.RailwayFenceEncryptionStrategy(input, key);
                }
                catch (FormatException err)
                {
                    throw new ArgumentException("Ключ должен быть числом");
                }
                break;

            case "\"Ключевая фраза\"":
                result = new EncryptionStrategies.PassPhraseEncryptionStrategy(input, keyInput.Text); break;

            case "Метод поворачивающейся решетки":
                GridForm gridForm = new GridForm();
                if (gridForm.ShowDialog() == DialogResult.OK)
                {
                    result = new EncryptionStrategies.RotatingGridEncryptionStrategy(input, gridForm.GetGrid());
                }
                break;

            case "Шифр Вижинера":
                result = new EncryptionStrategies.VigenereEncryptionStrategy(input, keyInput.Text); break;

            case "Криптосистема Рабина":
                if (rabinKeyForm == null)
                {
                    rabinKeyForm = new RabinKeyForm(mode);
                }
                rabinKeyForm.Mode = mode;
                if (rabinKeyForm.ShowDialog() == DialogResult.OK)
                {
                    result = new EncryptionStrategies.RabinEncryptionStrategy(input, mode == Mode.Encrypt ? rabinKeyForm.PublicKey : rabinKeyForm.PrivateKey);
                }
                break;

            default:
                throw new ArgumentException("Выберите метод шифрования");
            }

            return(result);
        }
Пример #5
0
        public IFileReaderBuilder UseEncryption(EncryptionStrategy encryptionStrategy)
        {
            if (_fileReader == null)
            {
                InitFileReader(FileType.Text);
            }

            if (_fileType == FileType.Xml)
            {
                var reader = (XmlFileReader)_fileReader;
                reader.Strict = false;
            }

            _fileReader = new EncryptedFileReader(_fileReader, encryptionStrategy);
            return(this);
        }
Пример #6
0
        /// <summary>
        /// Encrypts the message and its attachments.
        /// </summary>
        /// <param name="encryptionStrategy"></param>
        internal void Encrypt(EncryptionStrategy encryptionStrategy)
        {
            if (encryptionStrategy == null)
            {
                throw new ArgumentNullException(nameof(encryptionStrategy));
            }

            encryptionStrategy.EncryptMessage();
            IsEncrypted = true;

            var securityHeader = CreateSecurityHeaderElement();

            encryptionStrategy.AppendEncryptionElements(securityHeader);

            _encryptionElements = securityHeader.ChildNodes;
        }
Пример #7
0
 public EncryptedFileReader(FileReader fileReader,
                            EncryptionStrategy encryptionStrategy)
     : base(fileReader)
 {
     _encryptionStrategy = encryptionStrategy;
 }
Пример #8
0
 public void SetEncryptionStrategy(EncryptionStrategy encryptionStrategy)
 {
     _encryptionStrategy = encryptionStrategy;
 }