/// <summary>
        /// Gets the certificate fingerprint with the given hashing algorithm
        /// </summary>
        /// <param name="certificate">X509Certificate2 to be compute fingerprint</param>
        /// <param name="hashAlgorithm">Hash algorithm for fingerprint</param>
        /// <returns>A byte array representing the certificate hash.</returns>
        public static byte[] GetHash(X509Certificate2 certificate, HashAlgorithmName hashAlgorithm)
        {
            if (certificate == null)
            {
                throw new ArgumentNullException(nameof(certificate));
            }

            return(hashAlgorithm.ComputeHash(certificate.RawData));
        }
        public static Task <PrimarySignature> TimestampSignature(ITimestampProvider timestampProvider, PrimarySignature primarySignature, HashAlgorithmName hashAlgorithm, SignaturePlacement target, ILogger logger)
        {
            Signature signatureToTimestamp = primarySignature;

            if (target == SignaturePlacement.Countersignature)
            {
                signatureToTimestamp = RepositoryCountersignature.GetRepositoryCountersignature(primarySignature);
            }

            var signatureValue = signatureToTimestamp.GetSignatureValue();
            var messageHash    = hashAlgorithm.ComputeHash(signatureValue);

            var timestampRequest = new TimestampRequest(
                SigningSpecifications.V1,
                messageHash,
                hashAlgorithm,
                target);

            return(timestampProvider.TimestampSignatureAsync(primarySignature, timestampRequest, logger, CancellationToken.None));
        }
Beispiel #3
0
 internal static byte[] GetHash(X509Certificate2 certificate, HashAlgorithmName hashAlgorithm)
 {
     return(hashAlgorithm.ComputeHash(certificate.RawData));
 }