Пример #1
0
        private void btnregjistro_Click(object sender, EventArgs e)
        {
            X509Certificate2 cert = GetCertificateFromStore("CN=RootCA");

            if (cert == null)
            {
                Console.WriteLine("Certificate 'CN=CERT_SIGN_TEST_CERT' not found.");
                Console.ReadLine();
            }
            string name    = emritxt.Text.Trim();
            string mbiemri = mbiemritxt.Text.Trim();
            string email   = emailtxt.Text.Trim();
            string title   = titullitxt.Text.Trim();
            string salary  = rrogatxt.Text.Trim();



            if (validate())
            {
                name = emritxt.Text.Trim();


                mbiemri = mbiemritxt.Text.Trim();


                DES des = new DES();


                string mesazhi = name + ":" + mbiemri + ":" + emailtxt.Text + ":" + passwordtxt.Text.Trim() + ":" + titullitxt.Text + ":" + rrogatxt.Text;
                Console.WriteLine(mesazhi);
                byte[] encrytedData = des.Enkripto(mesazhi);

                byte[] IV  = des.getIV();
                byte[] key = des.getKey();


                byte[] encryptedKey = EncryptDataOaepSha1(cert, key);

                Console.WriteLine(encryptedKey.Length);
                Console.WriteLine(Convert.ToBase64String(encryptedKey));

                Console.WriteLine(Convert.ToBase64String(key));
                Console.WriteLine(Convert.ToBase64String(DecryptDataOaepSha1(cert, encryptedKey)));


                string delimiter            = ".";
                string fullmessageEncrypted = Convert.ToBase64String(IV) + delimiter + Convert.ToBase64String(encryptedKey) + delimiter + Convert.ToBase64String(encrytedData);


                byte[] receivedData = client.SendAndReceive(Encoding.UTF8.GetBytes(fullmessageEncrypted));

                Console.WriteLine("qa qova :" + fullmessageEncrypted.Length);
                Console.WriteLine("IV:" + Convert.ToBase64String(IV));
                Console.WriteLine("Qelsi: " + Convert.ToBase64String(encryptedKey));
                Console.WriteLine("Mesazhi: " + Convert.ToBase64String(encrytedData));
                Console.WriteLine(Encoding.UTF8.GetString(des.Dekripto(Convert.ToBase64String(receivedData))));

                if (Encoding.UTF8.GetString(des.Dekripto(Convert.ToBase64String(receivedData))).Substring(0, 2) == "OK")
                {
                    MessageBox.Show("Registered successfully");
                    Login login = new Login();
                    this.Hide();
                    login.Show();
                }
                else
                {
                    MessageBox.Show("Regjistrimi deshtoi");
                }
            }
            else
            {
                MessageBox.Show("Te dhenat jane shenuar gabim");
            }
        }