Example #1
0
        public static XadesObject GetXadesObject(SigningKeyProvider provider, XadesInfo xadesInfo, string signatureid)
        {
            XadesObject xadesObject = new XadesObject();

            xadesObject.QualifyingProperties.Target = String.Format("#{0}", signatureid);
            xadesObject.QualifyingProperties.SignedProperties.Id = String.Format("{0}-signedprops", signatureid);
            SignedSignatureProperties signedSignatureProperties = xadesObject.QualifyingProperties.SignedProperties.SignedSignatureProperties;


            var             x509CertificateParser = new Org.BouncyCastle.X509.X509CertificateParser();
            X509Certificate bouncyCert            = x509CertificateParser.ReadCertificate(Convert.FromBase64String(xadesInfo.RawPK));

            var cert = new Cert
            {
                IssuerSerial =
                {
                    X509IssuerName   = GetOidRepresentation(bouncyCert.IssuerDN.ToString()),
                    X509SerialNumber = bouncyCert.SerialNumber.ToString()
                }
            };

            cert.CertDigest.DigestMethod.Algorithm = provider.DigestMethod;

            var rawCertData = Convert.FromBase64String(xadesInfo.RawPK);
            var pkHash      = HashAlgorithm.Create(provider.HashAlgorithmName);
            var hashValue   = pkHash.ComputeHash(rawCertData);

            cert.CertDigest.DigestValue = hashValue;

            signedSignatureProperties.SigningCertificate.CertCollection.Add(cert);

            signedSignatureProperties.SigningTime = GetSigningTimeOffset(xadesInfo.SigningDateTimeUTC, xadesInfo.TimeZoneOffsetMinutes);
            return(xadesObject);
        }
Example #2
0
        public static XadesObject GetXadesObject(XadesInfo xadesInfo, string signatureid)
        {
            XadesObject xadesObject = new XadesObject();
            xadesObject.QualifyingProperties.Target = String.Format("#{0}", signatureid);
            xadesObject.QualifyingProperties.SignedProperties.Id = String.Format("{0}-signedprops", signatureid);
            SignedSignatureProperties signedSignatureProperties = xadesObject.QualifyingProperties.SignedProperties.SignedSignatureProperties;


            var x509CertificateParser = new Org.BouncyCastle.X509.X509CertificateParser();
            X509Certificate bouncyCert = x509CertificateParser.ReadCertificate(Convert.FromBase64String(xadesInfo.RawPK));

            var cert = new Cert
            {
                IssuerSerial =
                {
                    X509IssuerName = GetOidRepresentation(bouncyCert.IssuerDN.ToString()),
                    X509SerialNumber = bouncyCert.SerialNumber.ToString()
                }
            };

            cert.CertDigest.DigestMethod.Algorithm = CPSignedXml.XmlDsigGost3411UrlObsolete;

            var rawCertData = Convert.FromBase64String(xadesInfo.RawPK);
            var pkHash = HashAlgorithm.Create("GOST3411");
            var hashValue = pkHash.ComputeHash(rawCertData);
            cert.CertDigest.DigestValue = hashValue;

            signedSignatureProperties.SigningCertificate.CertCollection.Add(cert);

            signedSignatureProperties.SigningTime = xadesInfo.SigningDateTimeUTC.AddMinutes(xadesInfo.TimeZoneOffsetMinutes);
            return xadesObject;
        }
Example #3
0
 public static XadesInfo GetXadesInfo(X509Certificate2 certificate)
 {
     XadesInfo xadesInfo = new XadesInfo();
     xadesInfo.RawPK = Convert.ToBase64String(certificate.GetRawCertData());
     xadesInfo.SigningDateTimeUTC = DateTime.UtcNow;
     TimeSpan delta = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now);
     xadesInfo.TimeZoneOffsetMinutes = Convert.ToInt32(delta.TotalMinutes);
     return xadesInfo;
 }
Example #4
0
        public static XadesInfo GetXadesInfo(X509Certificate2 certificate)
        {
            XadesInfo xadesInfo = new XadesInfo();

            xadesInfo.RawPK = Convert.ToBase64String(certificate.GetRawCertData());
            xadesInfo.SigningDateTimeUTC = DateTime.UtcNow;
            TimeSpan delta = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now);

            xadesInfo.TimeZoneOffsetMinutes = Convert.ToInt32(delta.TotalMinutes);
            return(xadesInfo);
        }
        private XadesSignedXml GetXadesSignedXml(XadesInfo xadesInfo, XmlDocument originalDoc)
        {
            var certificate = CertificateHelper.GetCertificateByThumbprint(TestIntegrationClientServer.CERTIFICATE_THUMBPRINT);
            Assert.IsNotNull(certificate);

            var signatureid = String.Format("xmldsig-{0}", Guid.NewGuid().ToString().ToLower());

            var xadesSignedXml = GisSignatureHelper.GetXadesSignedXml(certificate, originalDoc, signatureid, TestIntegrationClientServer.PRIVATE_KEY_PASSWORD);

            var keyInfo = GisSignatureHelper.GetKeyInfo(xadesInfo.RawPK);
            xadesSignedXml.KeyInfo = keyInfo;

            var xadesObject = GisSignatureHelper.GetXadesObject(xadesInfo, signatureid);
            xadesSignedXml.AddXadesObject(xadesObject);

            return xadesSignedXml;
        }