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

            string JSON = package.TimeStampCheck.ToString("s") + "-" + JsonConvert.SerializeObject(package.Package);

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

            return(true);
        }
Ejemplo n.º 2
0
        public static bool Sign(PackageDataSigned package, string CN)
        {
            if (package == null)
            {
                return(false);
            }
            if (package.Package == null)
            {
                return(false);
            }
            package.TimeStampCheck = DateTime.Now.ToUniversalTime();
            string JSON = package.TimeStampCheck.ToString("s") + "-" + JsonConvert.SerializeObject(package.Package);

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