Esempio n. 1
0
        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            if (this.comboBox1.SelectedIndex == 0)
            {
                string       seckey  = "tjlx4Xd_dXa6xsC3pq-uX92h";
                DESEncryptor cryptor = new DESEncryptor(seckey);
                this.txtEncrypt.Text = cryptor.Encrypt(this.txtPlain.Text);
            }
            if (this.comboBox1.SelectedIndex == 1)
            {
                RSAEncryptor cryptor = new RSAEncryptor(null, null);
                this.txtEncrypt.Text = cryptor.Encrypt(this.txtPlain.Text);
            }
            if (this.comboBox1.SelectedIndex == 2) //HMACSHA256
            {
                RSAEncryptor cryptor = new RSAEncryptor(null, null);
                this.txtEncrypt.Text = cryptor.Encrypt(this.txtPlain.Text);
            }
            else
            {
                string   pwd = "800:6cc3cfc47dbd03c1cbc60398b0988a:186e5678c8b40921e56e847807b7de";
                string[] arr = pwd.Split(':');


                HMACSHA1Encryptor eb = new HMACSHA1Encryptor(arr[1], Convert.ToInt32(arr[0]));

                string arreer = eb.Encrypt("1");
            }
        }
Esempio n. 2
0
        private void EncryptFile()
        {
            byte[]     message   = File.ReadAllBytes(openFileDialog.FileName);
            BigInteger p         = BigInteger.Parse(p_textBox.Text);
            BigInteger q         = BigInteger.Parse(q_textBox.Text);
            BigInteger closedKey = BigInteger.Parse(closedKey_textBox.Text);
            BigInteger eulerFunc = Helper.CalcEulerFunc(p, q);
            BigInteger key       = Helper.CalcMultiplicativeInverseKey(eulerFunc, closedKey);

            ushort[] result = new ushort[message.Length];
            try
            {
                result = RSAEncryptor.Encrypt(message, key, p * q);
            }
            catch (ArithmeticException ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string resultText = "";

            foreach (var num in result)
            {
                resultText += num.ToString() + " ";
            }

            result_textBox.Text = resultText;
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                File.WriteAllBytes(saveFileDialog.FileName, Helper.ToByteArray(result));
            }
        }
Esempio n. 3
0
        public void ThrowsIfMessageIsTooLongForSpecifiedKey(byte[] message, string pubKey)
        {
            // Arrange
            var keyParser = new PemRSAKeyParser();
            var target    = new RSAEncryptor();

            keyParser.TryParsePublic(pubKey, out RSAParameters publicKey);

            // Act/Assert
            var ex = Assert.ThrowsAny <CryptographicException>(() => target.Encrypt(message, publicKey));
        }
Esempio n. 4
0
        public void EncryptsAndDecryptsMessages(byte[] message, string pubKey, string privKey)
        {
            // Arrange
            var keyParser = new PemRSAKeyParser();
            var target    = new RSAEncryptor();

            keyParser.TryParsePublic(pubKey, out RSAParameters publicKey);
            keyParser.TryParsePrivate(privKey, out RSAParameters privateKey);

            // Act
            var encryptedMessage = target.Encrypt(message, publicKey);
            var decryptedMessage = target.Decrypt(encryptedMessage, privateKey);

            // Assert
            Assert.Equal(message, decryptedMessage);
        }