Exemple #1
0
        /// <summary>
        /// Zwraca opis pliku pozwalający na zweryfikowanie czasu
        /// </summary>
        /// <param name="path">ścieżka lokalna do pliku do podpisania</param>
        /// <returns>ścieżka dostępu do podpisu danego pliku</returns>
        public FileDescription TagLocalFile(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentException("We have no path:(");
            }
            if (!File.Exists(path))
            {
                throw new FileNotFoundException("We have no " + path + "on local machine", path);
            }
            FileDescription description = new FileDescription();
            TimeRefresher   refresher   = new TimeRefresher();
            DateTime        tm          = DateTime.Now;
            string          ServerPath  = "time.windows.com"; //potem się z configa pociągnie
            var             IsSet       = refresher.RefreshOSTime(ServerPath);

            if (IsSet)
            {
                description.SyncFrom = ServerPath;
                tm = refresher.LastSet;
            }
            description.SignTime = tm;
            description.FileName = path;
            using (var md5 = MD5.Create())
            {
                using (var stream = File.OpenRead(path))
                {
                    var hash = md5.ComputeHash(stream);
                    description.Checksum = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
                }
            }
            return(description);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            TimeRefresher refresher = new TimeRefresher();
            var           IsSet     = refresher.RefreshOSTime("time.windows.com"); //potem się pomyśli nad załadowaniem z zewnątrz

            if (IsSet)
            {
                Console.WriteLine("Time is set as " + refresher.LastSet.ToString());
            }
            else
            {
                Console.WriteLine("Set time rejected");
            }
            Console.ReadKey();
        }