Пример #1
0
        static void Main(string[] args)
        {
            var clearText = "This is a sample message";

            byte[] enc = cryptoProvider.Encrypt(clearText);

            var blocks    = (int)Math.Ceiling((double)enc.Count() / BlockSize);
            var lastBlock = enc.GetBlock(blocks - 1, BlockSize);
            var mixBlock  = enc.GetBlock(blocks - 2, BlockSize);

            var padLength = FindPaddingLength(mixBlock, lastBlock, lastBlock.Length - 1, 0);

            Console.WriteLine("Padding : " + padLength + " (" + requests + " requests)");

            var res = new byte[blocks - 1][];

            Parallel.For(1, blocks,
                         i => res[i - 1] = DecryptBlock(enc, i, padLength)
                         );

            var result = res.SelectMany(x => x).ToList();

            result = result.TakeWhile((b, ix) => ix < (result.Count - padLength)).ToList();

            Console.WriteLine();
            Console.WriteLine("Requests  : " + requests + " (" + ((double)requests / enc.Length) + " req/byte)");
            Console.WriteLine("Decrypted : " + UTF8Encoding.UTF8.GetString(result.ToArray(), 0, result.Count));

            Console.ReadKey();
        }
Пример #2
0
 // ##########################################################################################
 /// <summary> Funkcja szyfrująca wewnętrznie wiadomość. </summary>
 /// <param name="crypt"> Klasa szyfrująca. </param>
 /// <param name="publicKey"> Klucz publiczny. </param>
 public void Encrypt(ICrypt crypt, string publicKey)
 {
     if (crypt == null)
     {
         return;
     }
     this.message = crypt.Encrypt(this.message, publicKey);
 }
Пример #3
0
        public Task <int> Create(User user)
        {
            var encriptedPassword = _crypt.Encrypt(user.Password);

            user.Password = encriptedPassword;
            _context.Users.AddAsync(user);
            var result = _context.SaveChangesAsync();

            return(result);
        }
Пример #4
0
        public int Crypt(Stream stream, long offset, byte[] buff, byte[] key)
        {
            stream.Seek(offset, SeekOrigin.Begin);
            var readBytes = stream.Read(buff, 0, buff.Length);

            var encrypted = crypter.Encrypt(buff, key);

            stream.Seek(offset, SeekOrigin.Begin);
            stream.Write(encrypted, 0, readBytes);

            return(readBytes);
        }
Пример #5
0
        public async Task <User> GetByEmailAndPassword(string email, string password)
        {
            var encriptedPassword = _crypt.Encrypt(password);

            var users = await _context.Users.ToListAsync();

            var query = from user in users
                        where user.Email == email && user.Password == encriptedPassword
                        select user;

            return(query.FirstOrDefault());
        }
Пример #6
0
        // ------------------------------------------------------------------------------------------
        private void ButtonElGamalCrypt_Click(object sender, EventArgs e)
        {
            string result = elgamal.Encrypt(textBoxElGamalCrypt.Text, elgamal.GetPublicKey());

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

            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);
             */
        });
    }