Пример #1
0
 private void GenerateKey()
 {
     cr   = new FiRandom(instancePin ^ BitConverter.ToInt64(Fi.Tech.ComputeHash(instanceSecret), 0));
     _Key = new byte[16];
     _Iv  = new byte[16];
     for (int i = 0; i < _Key.Length; i++)
     {
         _Key[i] = (byte)cr.Next(byte.MaxValue);
     }
     for (int i = 0; i < _Iv.Length; i++)
     {
         _Iv[i] = (byte)cr.Next(byte.MaxValue);
     }
 }
Пример #2
0
        public static HourlySyncCode Generate(DateTime KeyMoment, String Password = null)
        {
            Password = "******" + (Password ?? "");
            var      mins = (long)(TimeSpan.FromTicks(KeyMoment.Ticks)).TotalMinutes;
            FiRandom cs   = new FiRandom(mins);

            byte[] barr = new byte[64];
            for (int i = 0; i < barr.Length; i++)
            {
                barr[i] = (byte)cs.Next(256);
            }
            var hash = Fi.Tech.ComputeHash(Password);
            int passCount;

            passCount = 16;
            while (passCount-- > 0)
            {
                for (int i = 0; i < Password.Length; i++)
                {
                    var place = cs.Next(0, barr.Length);
                    barr[place] ^= (byte)Password[i];
                }
            }
            passCount = 16;
            while (passCount-- > 0)
            {
                for (int i = 0; i < hash.Length; i++)
                {
                    var place = cs.Next(0, barr.Length);
                    barr[place] ^= (byte)hash[i];
                    hash[i]     += barr[place];
                }
            }

            return(new HourlySyncCode(barr));
        }