Пример #1
0
        /// <summary>
        /// In the file was changed or the timestamp signature is altered, an exception will be thrown.
        /// </summary>
        /// <param name="originalFile"></param>
        /// <param name="timestampToken"></param>
        /// <returns></returns>
        public static bool IsTsaReponseFileValid(byte[] originalFile, byte[] timestampToken)
        {
            bool flag;

            try
            {
                TimestampInfo infoFromTsaResponse = TimestampInfo.GetInfoFromTsaResponse(timestampToken);
                if (infoFromTsaResponse == null || infoFromTsaResponse.HashAlgorithm == null)
                {
                    throw new Exception("The timestamp token is not a valid timestamp response.");
                }
                if (infoFromTsaResponse.IsTimestampAltered)
                {
                    throw new Exception("The timestamp response is altered.");
                }
                byte[] numArray = TimestampInfo.ComputeHash(originalFile, infoFromTsaResponse.HashAlgorithm);
                if (!TimestampInfo.CompareHashes(infoFromTsaResponse.OriginalDataHash, numArray))
                {
                    throw new Exception("The hash that appear on the timestamp response is not identical with the calculated file hash.");
                }
                flag = true;
            }
            catch
            {
                throw;
            }
            return(flag);
        }
Пример #2
0
        public static TimestampInfo GetInfoFromTsaResponse(byte[] timestampToken)
        {
            TimestampInfo timestampInfo;

            try
            {
                TimeStampResponse timeStampResponse = new TimeStampResponse(timestampToken);
                timestampInfo = new TimestampInfo(timeStampResponse.TimeStampToken.GetEncoded());
            }
            catch
            {
                try
                {
                    timestampInfo = new TimestampInfo(timestampToken);
                }
                catch
                {
                    timestampInfo = null;
                }
            }
            return(timestampInfo);
        }