Exemple #1
0
        private async void computeHashBtn_Click(object sender, EventArgs e)
        {
            byte[]             data = Encoding.ASCII.GetBytes(this.tigerInputTxtBox.Text);
            EncryptTextMessage msg  = new EncryptTextMessage()
            {
                Data      = data,
                Algorithm = AlgorithmType.TigerHash
            };

            byte[] response = await Task.Run(() => Crypto.EncryptText(msg));

            //byte[] response = Crypto.EncryptText(msg);

            StringBuilder hex = new StringBuilder(response.Length * 2);

            foreach (byte b in response)
            {
                hex.AppendFormat("{0:x2}", b);
            }

            if (response != null)
            {
                this.hashValueTxtBox.Text = hex.ToString();
            }
        }
Exemple #2
0
        private async void rsaDecryptTxtBtn_Click(object sender, EventArgs e)
        {
            if ((PTxtBox.Text != "") && (QTxtBox.Text != "") && (ETxtBox.Text != "") && (rsaCryptedTxtBox.Text != ""))
            {
                RSA rsa = new RSA();
                rsa.P = BigInteger.Parse(PTxtBox.Text);
                rsa.Q = BigInteger.Parse(QTxtBox.Text);
                rsa.E = BigInteger.Parse(ETxtBox.Text);
                //BigInteger data = BigInteger.Parse(rsaCryptedTxtBox.Text);
                BigInteger data = new BigInteger(Convert.FromBase64String(rsaCryptedTxtBox.Text));

                if (!rsa.MillerRabinTest(rsa.P, 10))
                {
                    MessageBox.Show("P mora biti prost broj. Izgenerisan je prost broj koji je najblizi unetom broju.");
                    rsa.P        = rsa.GenerateNearestPrime(rsa.P);
                    PTxtBox.Text = rsa.P.ToString();
                }
                if (!rsa.MillerRabinTest(rsa.Q, 10))
                {
                    MessageBox.Show("Q mora biti prost broj. Izgenerisan je prost broj koji je najblizi unetom broju.");
                    rsa.Q        = rsa.GenerateNearestPrime(rsa.Q);
                    QTxtBox.Text = rsa.Q.ToString();
                }
                rsa.CalculateN();
                //if (data > rsa.N)
                //{
                //    MessageBox.Show("P i Q moraju biti veci brojevi kako bi N bilo vece ili jednako od podatka.");
                //    return;
                //}
                rsa.CalculatePhi();
                if (BigInteger.GreatestCommonDivisor(rsa.Phi, rsa.E) != 1)
                {
                    MessageBox.Show("E mora biti uzajamno prosto sa Phi. Izgenerisano je najblize E koje ispunjava uslov.");
                    rsa.GeneratePublicKey();    // trazi se prvo E koje ispunjava uslov
                    ETxtBox.Text = rsa.E.ToString();
                }
                EncryptTextMessage msg = new EncryptTextMessage()
                {
                    Data      = data.ToByteArray(),
                    P         = rsa.P.ToByteArray(),
                    Q         = rsa.Q.ToByteArray(),
                    Key       = rsa.E.ToByteArray(),
                    Algorithm = AlgorithmType.RSA
                };
                byte[] response = await Crypto.DecryptText(msg);

                if (response != null)
                {
                    rsaDecryptedTxtBox.Text = Encoding.ASCII.GetString(response);
                    //rsaDecryptedTxtBox.Text = new BigInteger(response).ToString();
                }
            }
            else
            {
                MessageBox.Show("Potrebna polja nisu popunjena.");
            }
        }
Exemple #3
0
        // Dekriptovanje teksta
        public static async Task <byte[]> DecryptText(EncryptTextMessage msg)
        {
            byte[] decryptedText = null;
            try
            {
                decryptedText = await Task.Run(() => ServiceDriver.Instance.DecryptText(msg));
            }
            catch (Exception e)
            {
                MessageBox.Show("Doslo je do greske pri dekriptovanju teksta.");
            }

            return(decryptedText);
        }
Exemple #4
0
        /// <summary>
        /// Dekriptovanje teksta A52
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void A52decryptBtn_Click(object sender, EventArgs e)
        {
            if (((this.A52CtrModeCbox.Checked != true) && (this.A52KeyTxtBox.Text != "") && (this.A52cryptedTxt.Text != "") && (this.f22TxtBox.Text != "")) ||
                ((this.A52CtrModeCbox.Checked == true) && (this.A52KeyTxtBox.Text != "") && (this.A52cryptedTxt.Text != "") && (this.A52IVtxtBox.Text != "") && (this.f22TxtBox.Text != "")))
            {
                byte[] data = Convert.FromBase64String(this.A52cryptedTxt.Text);
                byte[] key  = Encoding.ASCII.GetBytes(this.A52KeyTxtBox.Text);
                string f    = this.f22TxtBox.Text;

                EncryptTextMessage msg = new EncryptTextMessage()
                {
                    Data    = data,
                    Key     = key,
                    FKeyA52 = f
                };

                if (this.A52CtrModeCbox.Checked == true)
                {
                    msg.Algorithm = AlgorithmType.A52CTR;
                    byte[] iv = Encoding.ASCII.GetBytes(this.A52IVtxtBox.Text);
                    msg.IV = iv;
                }
                else
                {
                    msg.Algorithm = AlgorithmType.A52;
                }

                byte[] response = await Task.Run(() => Crypto.DecryptText(msg));

                if (response != null)
                {
                    this.A52decryptedTxt.Text = Encoding.ASCII.GetString(response);
                }
            }
            else
            {
                MessageBox.Show("Polja nisu popunjena.");
            }
        }
Exemple #5
0
        private async void rc4CryptTxtBtn_Click(object sender, EventArgs e)
        {
            if (((this.rc4CtrCbx.Checked != true) && (this.rc4KeyTxtBox.Text != "") && (this.rc4InputTxtBox.Text != "")) ||
                ((this.rc4CtrCbx.Checked == true) && (this.rc4KeyTxtBox.Text != "") && (this.rc4InputTxtBox.Text != "") && (this.rc4IVTxtBox.Text != "")))
            {
                byte[] data = Encoding.ASCII.GetBytes(this.rc4InputTxtBox.Text);
                byte[] key  = Encoding.ASCII.GetBytes(this.rc4KeyTxtBox.Text);

                EncryptTextMessage msg = new EncryptTextMessage()
                {
                    Data = data,
                    Key  = key,
                };

                if (this.rc4CtrCbx.Checked == true)
                {
                    msg.Algorithm = AlgorithmType.RC4CTR;
                    byte[] iv = Encoding.ASCII.GetBytes(this.rc4IVTxtBox.Text);
                    msg.IV = iv;
                }
                else
                {
                    msg.Algorithm = AlgorithmType.RC4;
                }

                byte[] response = await Task.Run(() => Crypto.EncryptText(msg));

                if (response != null)
                {
                    this.rc4CryptedTxtBox.Text = Convert.ToBase64String(response);
                }
            }
            else
            {
                MessageBox.Show("Polja nisu popunjena.");
            }
        }