示例#1
0
 public static bool ValidateSessionID(Guid sessionID, byte[] machine = null)
 {
     try
     {
         var date = sessionID.GetDate();
         if (date > DateTime.UtcNow.AddYears(1) || date < DateTime.UtcNow.AddYears(-1))
         {
             return(false);
         }
         if (machine == null)
         {
             machine = MachineHelper.GetMachineHash();
         }
         var id = sessionID.ToByteArray();
         for (int i = 0; i < 6; i++)
         {
             if (id[id.Length - 12 + i] != machine[machine.Length - 6 + i])
             {
                 return(false);
             }
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
示例#2
0
        public static Guid GenerateSessionID(byte[] machine = null)
        {
            var id = GuidHelper.NewComb().ToByteArray();

            if (machine == null)
            {
                machine = MachineHelper.GetMachineHash();
            }
            Array.Copy(machine, machine.Length - 6, id, id.Length - 12, 6);
            return(new Guid(id));
        }
示例#3
0
        public static ISession RenewSession(SessionRequest m)
        {
            IStateName proxy = XmlRpcProxyGen.Create <IStateName>();

            proxy.Url     = ConstantsHelper.PROVIDER_URL_DEFAULT;
            m.Nonce       = GuidHelper.Nonce;
            m.MachineHash = Convert.ToBase64String(MachineHelper.GetMachineHash());
            var response = proxy.RenewSession(m.Encrypt <SessionRequest>(ConstantsHelper.KEY_PUBLIC_DEFAULT));

            if (string.IsNullOrWhiteSpace(response))
            {
                return(null);
            }
            return(CryptographyHelper.VerifyAndDeserialize <SessionRequest>(response, ConstantsHelper.KEY_PUBLIC_DEFAULT));
        }