public override byte[] GetSignatureValue()
 {
     using (ICms cms = CmsFactory.Create(_primarySignature.GetBytes()))
     {
         return(cms.GetRepositoryCountersignatureSignatureValue());
     }
 }
 public override byte[] GetSignatureValue()
 {
     using (ICms cms = CmsFactory.Create(SignedCms.Encode()))
     {
         return(cms.GetPrimarySignatureSignatureValue());
     }
 }
Exemple #3
0
        private static PrimarySignature CreateRepositoryCountersignature(CmsSigner cmsSigner, PrimarySignature primarySignature, CngKey privateKey)
        {
            using (ICms primarySignatureCms = CmsFactory.Create(primarySignature.GetBytes()))
            {
                primarySignatureCms.AddCountersignature(cmsSigner, privateKey);

                var bytes      = primarySignatureCms.Encode();
                var updatedCms = new SignedCms();

                updatedCms.Decode(bytes);

                return(PrimarySignature.Load(updatedCms));
            }
        }
        /// <summary>
        /// Timestamps data present in the TimestampRequest.
        /// </summary>
        public async Task <PrimarySignature> TimestampSignatureAsync(PrimarySignature primarySignature, TimestampRequest request, ILogger logger, CancellationToken token)
        {
            SignedCms timestampCms = await GetTimestampAsync(request, logger, token);

            using (ICms signatureCms = CmsFactory.Create(primarySignature.GetBytes()))
            {
                if (request.Target == SignaturePlacement.Countersignature)
                {
                    signatureCms.AddTimestampToRepositoryCountersignature(timestampCms);
                }
                else
                {
                    signatureCms.AddTimestamp(timestampCms);
                }
                return(PrimarySignature.Load(signatureCms.Encode()));
            }
        }
        private static SignedCms EnsureCertificatesInCertificatesCollection(
            SignedCms timestamp,
            IReadOnlyList <X509Certificate2> chain)
        {
            using (ICms timestampCms = CmsFactory.Create(timestamp.Encode()))
            {
                timestampCms.AddCertificates(
                    chain.Where(certificate => !timestamp.Certificates.Contains(certificate)));

                var bytes      = timestampCms.Encode();
                var updatedCms = new SignedCms();

                updatedCms.Decode(bytes);

                return(updatedCms);
            }
        }