Пример #1
0
        private static void DemoCryptAlgorithm(ICrypt algorithm, string message)
        {
            var encryptMessage   = algorithm.Crypt(message);
            var decryptedMessage = algorithm.Decrypt(encryptMessage);

            Console.WriteLine(encryptMessage);
            Console.WriteLine(decryptedMessage);
            Console.WriteLine();
        }
Пример #2
0
 // ------------------------------------------------------------------------------------------
 /// <summary> Funkcja deszyfrująca wewnętrznie wiadomość. </summary>
 /// <param name="crypt"> Klasa szyfrująca. </param>
 /// <param name="decrypt"> Informacja czy wiadomość jest zaszyfrowana. </param>
 public void Decrypt(ICrypt crypt, bool decrypt)
 {
     if (crypt == null)
     {
         return;
     }
     if (decrypt)
     {
         this.message = crypt.Decrypt(this.message);
     }
 }
Пример #3
0
        private Task <TokenResponse> AuthorizeByHandshakeSecretAsync(CertificateAuthenticationResponse authResponse, IOpenIdClient openId, OpenIdAuthenticationOptions options, TimeSpan?timeout)
        {
            var request = new CertificateTokenRequest(
                cryptoProvider.Decrypt(authResponse.EncryptedKey),
                credentials.PublicKeyCertificate.Thumbprint,
                options.Scope,
                options.ClientId,
                options.ApiKey);

            return(openId.RequestTokenAsync(request, timeout));
        }
Пример #4
0
 public static bool IsPaddingValid(byte[] iv, byte[] byteArray)
 {
     try
     {
         requests++;
         cryptoProvider.Decrypt(iv, byteArray);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #5
0
        private void readThreadWorker()
        {
            ushort totalsize = 0;
            bool   complete  = true;

            byte[] buffer;

            while (this.running && this.connection.Connected)
            {
                // Daten zum lesen vorhanden?
                if (this.connection.Available > 2)
                {
                    if (complete)
                    {
                        complete  = false;
                        totalsize = this.connectionReader.ReadUInt16();

                        // ist das nächste Packet komplett im Empfangspuffer?
                        if (this.connection.Available >= totalsize - 2)
                        {
                            // buffer Array erstellen
                            buffer = new byte[totalsize];
                            this.connectionReader.ReadBytes(totalsize - 2).CopyTo(buffer, 2);

                            // Alles empfangen
                            complete = true;

                            // decrypt
                            cryptor.Decrypt(buffer, 2, buffer.Length);

                            // syncronize
                            lock (this.readQueue)
                            {
                                // der ReadQueue hinzufügen
                                this.readQueue.Enqueue(new L2BasePacket(buffer));
                            }
                        }
                    }
                    else
                    {
                        // packet endlich komplett im Empfangspuffer?
                        if (this.connection.Available >= totalsize - 2)
                        {
                            buffer = new byte[totalsize];
                            this.connectionReader.ReadBytes(totalsize - 2).CopyTo(buffer, 2);

                            cryptor.Decrypt(buffer, 0, buffer.Length);

                            complete = true;
                            // syncronize
                            lock (this.readQueue)
                            {
                                this.readQueue.Enqueue(new L2BasePacket(buffer));
                            }
                        }
                    }
                }
                try
                {
                    Thread.Sleep(1);
                }
                catch (ThreadInterruptedException)
                {
                    // alles bestens
                }
            }
        }
Пример #6
0
        // ------------------------------------------------------------------------------------------
        private void ButtonElGamalDecrypt_Click(object sender, EventArgs e)
        {
            string result = elgamal.Decrypt(textBoxElGamalCrypt.Text);

            textBoxElGamalDecrypt.Text = result;
        }
Пример #7
0
        // ------------------------------------------------------------------------------------------
        private void ButtonRSADecrypt_Click(object sender, EventArgs e)
        {
            string result = ersa.Decrypt(textBoxRSACrypt.Text);

            textBoxRSADecrypt.Text = result;
        }
Пример #8
0
    public override void Init()
    {
        IEventHandler h = App.On(ApplicationEvents.ON_INITED, (sender, e) => {
            Debug.Log("9123891237012897312");
        });

        IEventHandler aa = App.On(ApplicationEvents.ON_INITED, (sender, e) => {
            Debug.Log("aksldjalkds9123891237012897312");
        });

        IEventHandler bb = App.On(ApplicationEvents.ON_INITED, (sender, e) => {
            Debug.Log("ooooooooo9123891237012897312");
        });


        App.On(ApplicationEvents.ON_APPLICATION_START_COMPLETE, (sender, e) =>
        {
            h.Cancel();

            App.Event.Trigger(ApplicationEvents.ON_INITED);

            Debug.Log(App.Make <Test>("123"));

            IHash hash = App.Make <IHash>();
            //Debug.Log(hash.Bcrypt("helloworld"));

            ICrypt secret = App.Make <ICrypt>();
            string code   = secret.Encrypt("helloworld");
            Debug.Log(code);

            Debug.Log(secret.Decrypt(code));

            FThread.Instance.Task(() =>
            {
                Debug.Log("pppppppppppppppppppp");
                int i = 0;
                i++;
                return(i);
            }).Delay(5).Start().Cancel();

            //Debug.Log(hash.BcryptVerify("helloworld", "$2a$10$Y8BxbHFgGArGVHIucx8i7u7t5ByLlSdWgWcQc187hqFfSiKFJfz3C"));
            //Debug.Log(hash.BcryptVerify("helloworld", "$2a$15$td2ASPNq.8BXbpa6yUU0c.pQpfYLxtcbXviM8fZXw4v8FDeO3hCoC"));

            IResources res      = App.Make <IResources>();
            IAssetBundle bundle = App.Make <IAssetBundle>();
            //Object.Instantiate(res.Load<GameObject>("prefab/asset6/test-prefab.prefab"));

            //Object[] p = res.LoadAll("prefab/asset6");

            res.LoadAsync <GameObject>("prefab/asset6/test-prefab", (obj) =>
            {
                Object.Instantiate(obj);
            });
            //res.UnloadAll();
            //Object.Instantiate(res.Load<GameObject>("prefab/asset6/test-prefab.prefab"));

            /*
             * Thread subThread = new Thread(new ThreadStart(() => {
             *
             *  App.MainThread(() => { new GameObject(); });
             *
             * }));
             *
             * FThread.Instance.Task(() =>
             * {
             *  int i = 0;
             *  i++;
             *  return i;
             * }).Delay(5).OnComplete((obj) => Debug.Log("sub thread complete:" + obj)).Start();
             *
             * subThread.Start();
             *
             */


            /*
             * ITimeQueue timeQueue = App.Time.CreateQueue();
             *
             * ITimeTaskHandler h = timeQueue.Task(() =>
             * {
             *  Debug.Log("this is in task");
             * }).Delay(3).Loop(3).Push();
             *
             *
             * timeQueue.Task(() =>
             * {
             *  Debug.Log("2222222");
             * }).Delay(1).Loop(3).OnComplete(()=> { h.Cancel(); Debug.Log("2 complete"); }).Push();
             *
             * timeQueue.Task(() =>
             * {
             *  Debug.Log("rand!");
             * }).Loop(() => { return Random.Range(0,100) > 10; }).Push();
             *
             * timeQueue.OnComplete(() =>
             * {
             *  Debug.Log("queueComplete");
             * });
             *
             * timeQueue.Play();
             *
             *
             * FThread.Instance.Task(() =>
             * {
             *  Debug.Log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
             *  //Debug.Log(App.Time.Time);
             *  timeQueue.Replay();
             *
             * }).Delay(9).Start();*/



            /*
             *
             * App.On(HttpRequestEvents.ON_MESSAGE + typeof(IConnectorHttp).ToString(), (obj1, obj2) =>
             * {
             *
             *  Debug.Log((obj2 as IHttpResponse).Text);
             *  Debug.Log((obj2 as IHttpResponse).IsError);
             *  Debug.Log((obj2 as IHttpResponse).Error);
             *
             * });
             *
             * App.On(SocketRequestEvents.ON_MESSAGE + typeof(IConnectorSocket).ToString(), (obj1, obj2) =>
             * {
             *
             *  if ((obj2 as PackageResponseEventArgs).Response.Package is string)
             *  {
             *      Debug.Log((obj2 as PackageResponseEventArgs).Response.Package as string);
             *  }else
             *  {
             *      Debug.Log(Encoding.UTF8.GetString(((obj2 as PackageResponseEventArgs).Response.Package as byte[])));
             *  }
             *
             * });
             *
             * App.On(SocketRequestEvents.ON_CONNECT, (obj1, obj2) =>
             * {
             *
             *  Debug.Log("on connect");
             *
             * });
             *
             *
             * App.On(SocketRequestEvents.ON_ERROR, (obj1, obj2) =>
             * {
             *
             *  Debug.Log("on tcp error:" + (obj2 as ErrorEventArgs).Error.Message);
             *
             * });
             *
             * //链接配置见 NetworkConfig 配置文件
             *
             * IConnectorTcp tcpConnect = FNetwork.Instance.Create<IConnectorTcp>("tcp.text");
             *
             * (tcpConnect as IEvent).Event.One(SocketRequestEvents.ON_MESSAGE, (s1, e1) =>
             * {
             *  if ((e1 as PackageResponseEventArgs).Response.Package is string)
             *  {
             *      Debug.Log((e1 as PackageResponseEventArgs).Response.Package as string);
             *  }
             *  else
             *  {
             *      Debug.Log(Encoding.UTF8.GetString(((e1 as PackageResponseEventArgs).Response.Package as byte[])));
             *  }
             * });
             *
             * tcpConnect.Connect();
             * tcpConnect.Send("hello this is tcp msg with [text]".ToByte());
             *
             * IConnectorTcp tcpConnect2 = FNetwork.Instance.Create<IConnectorTcp>("tcp.frame");
             * tcpConnect2.Connect();
             * tcpConnect2.Send("hello this is tcp msg with [frame]".ToByte());
             *
             * IConnectorUdp udpConnect = FNetwork.Instance.Create<IConnectorUdp>("udp.bind.host.text");
             * udpConnect.Connect();
             * udpConnect.Send("hello this is udp msg with [text]".ToByte());
             *
             * IConnectorUdp udpConnectFrame = FNetwork.Instance.Create<IConnectorUdp>("udp.bind.host.frame");
             * udpConnectFrame.Connect();
             * udpConnectFrame.Send("hello this is udp msg with [frame]".ToByte());
             *
             * IConnectorUdp udpConnect2 = FNetwork.Instance.Create<IConnectorUdp>("udp.unbind.host.frame");
             * udpConnect2.Connect();
             * udpConnect2.Send("hello world(client udp)".ToByte() , "pvp.gift", 3301);
             */
        });
    }