Esempio n. 1
0
 /// <summary>
 /// Computes an attribute containing a time-stamp token of the provided data, from the provided TSA using the
 /// provided.
 /// </summary>
 /// <remarks>
 /// Computes an attribute containing a time-stamp token of the provided data, from the provided TSA using the
 /// provided. The hashing is performed by the method using the specified algorithm and a BouncyCastle provider.
 /// </remarks>
 /// <param name="signedData"></param>
 /// <exception cref="System.Exception">System.Exception</exception>
 protected internal virtual BcCms.Attribute GetTimeStampAttribute(DerObjectIdentifier oid
                                                                  , ITspSource tsa, AlgorithmIdentifier digestAlgorithm, byte[] messageImprint)
 {
     try
     {
         //jbonilla Hack para obtener el digest del TSA
         IDigest digest        = null;
         string  algorithmName = null;
         digest        = DigestUtilities.GetDigest(DigestAlgorithm.SHA1.GetName());
         algorithmName = DigestAlgorithm.SHA1.GetName();
         digest.BlockUpdate(messageImprint, 0, messageImprint.Length);
         byte[] r = new byte[digest.GetDigestSize()];
         digest.DoFinal(r, 0);
         byte[]            toTimeStamp = r;
         TimeStampResponse tsresp      = tsa.GetTimeStampResponse(DigestAlgorithm.GetByName(algorithmName)
                                                                  , toTimeStamp);
         TimeStampToken tstoken = tsresp.TimeStampToken;
         if (tstoken == null)
         {
             throw new ArgumentNullException("The TimeStampToken returned for the signature time stamp was empty."
                                             );
         }
         BcCms.Attribute signatureTimeStamp = new BcCms.Attribute(oid, new DerSet(Asn1Object.FromByteArray
                                                                                      (tstoken.GetEncoded())));
         return(signatureTimeStamp);
     }
     catch (IOException e)
     {
         throw new RuntimeException(e);
     }
     catch (NoSuchAlgorithmException e)
     {
         throw new RuntimeException(e);
     }
 }
        /// <summary>
        /// Computes an attribute containing a time-stamp token of the provided data, from the provided TSA using the
        /// provided.
        /// </summary>
        /// <remarks>
        /// Computes an attribute containing a time-stamp token of the provided data, from the provided TSA using the
        /// provided. The hashing is performed by the method using the specified algorithm and a BouncyCastle provider.
        /// </remarks>
        /// <param name="signedData"></param>
        /// <exception cref="System.Exception">System.Exception</exception>
        protected internal virtual BcCms.Attribute GetTimeStampAttribute(DerObjectIdentifier oid
                                                                         , ITspSource tsa, AlgorithmIdentifier digestAlgorithm, byte[] messageImprint)
        {
            try
            {
                //jbonilla Hack para obtener el digest del TSA
                IDigest digest        = null;
                string  algorithmName = null;
                if (tsa is ITSAClient)
                {
                    //TODO jbonilla - ¿AlgorithmIdentifier?
                    digest        = ((ITSAClient)tsa).GetMessageDigest();
                    algorithmName = digest.AlgorithmName;
                }
                else
                {
                    digest        = DigestUtilities.GetDigest(DigestAlgorithm.SHA1.GetName());
                    algorithmName = DigestAlgorithm.SHA1.GetName();
                }
                byte[] toTimeStamp = DigestAlgorithms.Digest(digest, messageImprint);

                TimeStampResponse tsresp = tsa.GetTimeStampResponse(DigestAlgorithm.GetByName(algorithmName)
                                                                    , toTimeStamp);
                TimeStampToken tstoken = tsresp.TimeStampToken;
                if (tstoken == null)
                {
                    throw new ArgumentNullException("The TimeStampToken returned for the signature time stamp was empty."
                                                    );
                }
                BcCms.Attribute signatureTimeStamp = new BcCms.Attribute(oid, new DerSet(Asn1Object.FromByteArray
                                                                                             (tstoken.GetEncoded())));
                return(signatureTimeStamp);
            }
            catch (IOException e)
            {
                throw new RuntimeException(e);
            }
            catch (NoSuchAlgorithmException e)
            {
                throw new RuntimeException(e);
            }
        }
		/// <summary>
		/// Computes an attribute containing a time-stamp token of the provided data, from the provided TSA using the
		/// provided.
		/// </summary>
		/// <remarks>
		/// Computes an attribute containing a time-stamp token of the provided data, from the provided TSA using the
		/// provided. The hashing is performed by the method using the specified algorithm and a BouncyCastle provider.
		/// </remarks>
		/// <param name="signedData"></param>
		/// <exception cref="System.Exception">System.Exception</exception>
		protected internal virtual BcCms.Attribute GetTimeStampAttribute(DerObjectIdentifier oid
			, ITspSource tsa, AlgorithmIdentifier digestAlgorithm, byte[] messageImprint)
		{
			try
			{
                //jbonilla Hack para obtener el digest del TSA
                IDigest digest = null;
                string algorithmName = null;
                if (tsa is ITSAClient)
                {
                    //TODO jbonilla - ¿AlgorithmIdentifier?
                    digest = ((ITSAClient)tsa).GetMessageDigest();
                    algorithmName = digest.AlgorithmName;                    
                }
                else
                {
                    digest = DigestUtilities.GetDigest(DigestAlgorithm.SHA1.GetName());
                    algorithmName = DigestAlgorithm.SHA1.GetName();
                }
                byte[] toTimeStamp = DigestAlgorithms.Digest(digest, messageImprint);

                TimeStampResponse tsresp = tsa.GetTimeStampResponse(DigestAlgorithm.GetByName(algorithmName)
                    , toTimeStamp);
				TimeStampToken tstoken = tsresp.TimeStampToken;
				if (tstoken == null)
				{
					throw new ArgumentNullException("The TimeStampToken returned for the signature time stamp was empty."
						);
				}
				BcCms.Attribute signatureTimeStamp = new BcCms.Attribute(oid, new DerSet(Asn1Object.FromByteArray
					(tstoken.GetEncoded())));
				return signatureTimeStamp;
			}
			catch (IOException e)
			{
				throw new RuntimeException(e);
			}
			catch (NoSuchAlgorithmException e)
			{
				throw new RuntimeException(e);
			}
		}