Beispiel #1
0
        public static bool Verify(FileUploadDataSigned FUD, byte[] cer)
        {
            if (FUD == null)
            {
                return(false);
            }
            if (FUD.Data == null)
            {
                return(false);
            }
            if (FUD.Data.TimeStampCheck > DateTime.Now.ToUniversalTime().AddMinutes(TimeStampPlusMinus) &&
                FUD.Data.TimeStampCheck < DateTime.Now.ToUniversalTime().AddMinutes(-TimeStampPlusMinus))
            {
                Debug.WriteLine("Timestamp missmatch -+" + TimeStampPlusMinus.ToString() + " minutes");
                return(false);
            }
            string JSON = JsonConvert.SerializeObject(FUD.Data, Formatting.None);

            if (Verify(Encoding.UTF8.GetBytes(JSON), FUD.Signature, cer) == false)
            {
                Debug.WriteLine("Verify failed");
                return(false);
            }
            return(true);
        }
Beispiel #2
0
        public static bool Sign(FileUploadDataSigned data, string CN)
        {
            if (data == null)
            {
                return(false);
            }
            if (data.Data == null)
            {
                return(false);
            }
            data.Data.TimeStampCheck = DateTime.Now.ToUniversalTime();
            string JSON = JsonConvert.SerializeObject(data.Data, Formatting.None);

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