示例#1
0
 private void EncryptOperationTo()
 {
     try
     {
         crypter = new Crypter();
         var    operation     = DetermineOpearation();
         var    operationAsn1 = Asn1Formatter.SetCommandAsn1((int)Cmd.cipher);
         byte[] buffer;
         handler.Send(operationAsn1);
         data = handler.Recieve();
         var text     = (string)CerificatesBox.Invoke(new Func <string>(() => CerificatesBox.Text));
         var asn1Cert = Asn1Formatter.SetCertNameAsn1(Encoding.ASCII.GetBytes(text));
         handler.Send(asn1Cert);
         data = handler.Recieve();
         byte[] cert = Asn1Formatter.GetCertAsn1(data);
         crypter.FromBytesToCert(cert);
         byte[] symivBytes = Asn1Formatter.SetSymKeyAndIVAsn1(crypter.GetEncryptedSymKey(), crypter.IV);
         handler.Send(symivBytes);
         data = handler.Recieve();
         if (Encoding.ASCII.GetString(Asn1Formatter.GetCertAsn1(data)) == "ESTABLISHED")
         {
             text   = (string)textBox1.Invoke(new Func <string>(() => textBox1.Text));
             buffer = crypter.Encrypt(Encoding.ASCII.GetBytes(text));
             handler.Send(buffer);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
示例#2
0
 private void SignOperationTo()
 {
     try
     {
         var operation     = DetermineOpearation();
         var operationAsn1 = Asn1Formatter.SetCommandAsn1((int)Cmd.sign);
         handler.Send(operationAsn1);
         data = handler.Recieve();
         if (Encoding.ASCII.GetString(Asn1Formatter.GetCertAsn1(data)) == "ESTABLISHED")
         {
             int certIndex = (int)CerificatesBox.Invoke(new Func <int>(() => CerificatesBox.SelectedIndex));
             handler.Send(crypter.Sign(Encoding.ASCII.GetBytes(textBox1.Text), certIndex));
         }
         else
         {
             throw new Exception("Error while send");
         }
     }
     catch (NullReferenceException ne)
     {
         var errorCode = Asn1Formatter.SetCommandAsn1((int)Cmd.error);
         handler.Send(errorCode);
         MessageBox.Show(ne.Message);
         Console.WriteLine(ne.Message);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }