Exemplo n.º 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);
     }
 }
Exemplo n.º 2
0
 private void NewRid()
 {
     lock ("GLOBAL_RID_GENERATION") {
         Buffer.BlockCopy(RidSessionSegment.Value, 0, Signature, 0, 8);
         Buffer.BlockCopy(BitConverter.GetBytes(DateTime.UtcNow.Ticks), 0, Signature, 8, 8);
         Buffer.BlockCopy(CSeg, 0, Signature, 16, 8);
         Buffer.BlockCopy(BitConverter.GetBytes(rng.Next()), 0, Signature, 24, 4);
         Buffer.BlockCopy(BitConverter.GetBytes(segmentEOrigin + ++segmentESequential), 0, Signature, 28, 4);
     }
 }
Exemplo n.º 3
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));
        }