Exemplo n.º 1
0
        public static bool Verify(PolicyObjectSigned policy, byte[] cer)
        {
            if (policy == null)
            {
                return(false);
            }
            if (policy.Policy == null)
            {
                return(false);
            }
            if (policy.Policy.TimeStampCheck > DateTime.Now.ToUniversalTime().AddMinutes(TimeStampPlusMinus) &&
                policy.Policy.TimeStampCheck < DateTime.Now.ToUniversalTime().AddMinutes(-TimeStampPlusMinus))
            {
                Debug.WriteLine("Timestamp missmatch -+" + TimeStampPlusMinus.ToString() + " minutes");
                return(false);
            }

            string JSON = JsonConvert.SerializeObject(policy.Policy, Formatting.None);

            if (Verify(Encoding.UTF8.GetBytes(JSON), policy.Signature, cer) == false)
            {
                Debug.WriteLine("Verify failed");
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public static bool Sign(PolicyObjectSigned policy, string CN)
        {
            if (policy == null)
            {
                return(false);
            }
            if (policy.Policy == null)
            {
                return(false);
            }
            policy.Policy.TimeStampCheck = DateTime.Now.ToUniversalTime();
            string JSON = JsonConvert.SerializeObject(policy.Policy, Formatting.None);

            policy.Signature = Sign(Encoding.UTF8.GetBytes(JSON), CN, StoreLocation.LocalMachine);
            if (policy.Signature == null)
            {
                return(false);
            }
            return(true);
        }