Beispiel #1
0
        public XmlSignatureModel(XmlSignature signature, IXmlPolicyMapperBySignature policyMapper = null)
        {
            Type        = signature.SignedEntityType;
            SigningTime = signature.SigningTime;
            if (signature.SignedElement != null)
            {
                SignedElement = new XmlElementModel(signature.SignedElement);
            }
            if (signature.SignatureAlgorithm != null && signature.SignatureValue != null)
            {
                Signature = new SignatureAlgorithmAndValueModel(signature.SignatureAlgorithm, signature.SignatureValue);
            }
            if (signature.PolicyIdentifier != null)
            {
                SignaturePolicy = new SignaturePolicyIdentifierModel(signature.PolicyIdentifier);
            }
            if (signature.SigningCertificate != null)
            {
                Certificate = new CertificateModel(signature.SigningCertificate);
            }
            if (signature.SignatureTimestamps.Any())
            {
                CertifiedDateReference = signature.SignatureTimestamps.First().EncapsulatedTimestamp.GenTime;
                Timestamps             = signature.SignatureTimestamps.Select(ts => new CadesTimestampModel(ts.EncapsulatedTimestamp)).ToList();
            }

            // Validate signature according to the provided policy.
            if (policyMapper != null)
            {
                var vr = signature.Validate(policyMapper);
                ValidationResults = new ValidationResultsModel(vr);
            }
        }
Beispiel #2
0
        private static void Method2()
        {
            Console.WriteLine("Press enter to start the test");
            Console.ReadLine();
            CryptoConfig.AddAlgorithm(typeof(RSAPKCS1SHA256SignatureDescription), "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256");

            // Create a new XML document.
            XmlDocument doc = new XmlDocument();

            // Format the document to ignore white spaces.
            doc.PreserveWhitespace = false;
            // Load the passed XML
            string my_xml = "<root><test>test</test></root>";

            doc.LoadXml(my_xml);

            ING.iDealAdvanced.Connector conn = new ING.iDealAdvanced.Connector();

            X509Certificate2         cert = conn.ClientCertificate;
            RSACryptoServiceProvider key  = null;// conn.GetMerchantRSACryptoServiceProvider();

            XmlSignature.Sign(ref doc, key, cert.Thumbprint);

            Console.WriteLine(doc.OuterXml);
            Console.WriteLine("");
            Console.WriteLine("");
            Console.WriteLine("");
            Console.WriteLine("Ended");
            Console.ReadLine();
        }
        public static void Main(string[] args)
        {
            // TODO: Remove personal info before commit.

            // Load configuration.
            var options = new AadhaarOptions();

            new ConfigurationBuilder()
            .AddJsonFile("appsettings.json")
            .Build()
            .GetSection("Aadhaar")
            .Bind(options);

            var signerAndVerifier = new XmlSignature
            {
                Signer   = new X509Certificate2(options.AuaSignatureKeyPath, "public", X509KeyStorageFlags.Exportable),
                Verifier = new X509Certificate2(options.UidaiSignatureKeyPath)
            };

            Auth.Options  = Bfd.Options = Otp.Options = Kyc.Options = options;
            Auth.Signer   = Bfd.Signer = Otp.Signer = Kyc.Signer = signerAndVerifier;
            Auth.Verifier = Bfd.Verifier = Kyc.Verifier = signerAndVerifier;
            Kyc.Decryptor = new KycDecryptor {
                KuaKey = signerAndVerifier.Signer
            };

            Auth.AuthenticateAsync().GetAwaiter().GetResult();
            // Bfd.DetectBestFingerAsync().GetAwaiter().GetResult();
            Kyc.KnowYourCustomerAsync().GetAwaiter().GetResult();

            Console.ReadLine();

            signerAndVerifier.Dispose();
        }
Beispiel #4
0
        public static void Main(string[] args)
        {
            var configuration = Configuration.GetConfiguration();

            Auth.Configuration = Bfd.Configuration = Otp.Configuration = Kyc.Configuration = configuration;

            var signerAndVerifier = new XmlSignature
            {
                Signer   = new X509Certificate2(configuration.AuaSignatureKeyPath, "public", X509KeyStorageFlags.Exportable),
                Verifier = new X509Certificate2(configuration.UidaiSignatureKeyPath)
            };

            Auth.Signer   = Bfd.Signer = Otp.Signer = Kyc.Signer = signerAndVerifier;
            Auth.Verifier = Bfd.Verifier = Kyc.Verifier = signerAndVerifier;

            // Just reference the signer key, as the signer and decryption key point to the same X.509 certificate.
            Kyc.Decryptor = new KycDecryptor {
                KuaKey = signerAndVerifier.Signer
            };

            Auth.AuthenticateAsync().GetAwaiter().GetResult();
            // Bfd.DetectBestFingerAsync().GetAwaiter().GetResult();
            // Kyc.KnowYourCustomerAsync().GetAwaiter().GetResult();

            Console.ReadLine();

            signerAndVerifier.Dispose();
        }
        public string Verify_Xml()
        {
            try
            {
                string fileName = "";

                HttpPostedFileBase file = Request.Files[0];     //Uploaded file
                                                                //Use the following properties to get file's name, size and MIMEType
                int fileSize = file.ContentLength;
                fileName = file.FileName;
                string           mimeType    = file.ContentType;
                System.IO.Stream fileContent = file.InputStream;
                if (!Directory.Exists(Server.MapPath("~/UploadFile/")))
                {
                    Directory.CreateDirectory(Server.MapPath("~/UploadFile/"));
                }

                //To save file, use SaveAs method
                string filePath = Server.MapPath("~/UploadFile/") + fileName;
                file.SaveAs(filePath);     //File will be saved in application root
                var itemp = this.Request.Form;
                var parr  = new Dictionary <string, string>();
                foreach (var key in itemp.AllKeys)
                {
                    parr.Add(key.ToLower(), itemp[key]);
                }

                var          serialNumber = parr["serialnumber"];
                bool         check        = false;
                XmlSignature cv           = new XmlSignature(serialNumber);
                try
                {
                    check = cv.VerifyDigitalSignature(filePath, 1);
                }catch (Exception ex)
                {
                    return("{\"result\":\"OK\",\"data\":\"ERROR\"}");
                }
                if (check)
                {
                    return("{\"result\":\"OK\",\"data\":\"SUCCESS\"}");
                }
                return("{\"result\":\"OK\",\"data\":\"ERROR\"}");
            }
            catch (Exception ex)
            {
                return("{\"result\":\"ERROR\",\"data\":[{\"status\":\"" + ex.Message.Replace("\n", "") + "\"}]}");
            }
        }
Beispiel #6
0
        public XmlSignatureModel(XmlSignature signature, ValidationResults validationResults)
        {
            ValidationModel  = new ValidationErrorModel(validationResults);
            SignedEntityType = signature.SignedEntityType;
            SigningTime      = signature.SigningTime;

            if (signature.SigningCertificate != null)
            {
                SigningCertificate = new CertificateModel(signature.SigningCertificate);
            }
            if (signature.SignedElement != null)
            {
                SignedElement = new XmlElementModel(signature.SignedElement);
            }
            if (signature.PolicyIdentifier != null)
            {
                SignaturePolicyId = signature.PolicyIdentifier.SigPolicyId;
            }
        }
        public string AddSignature(string xml)
        {
            _logger.Log("signing xml...");
            var xmlDoc = new XmlDocument();

            xmlDoc.PreserveWhitespace = true;
            xmlDoc.LoadXml(xml);

            var certificate = _configuration.SigningCertificate;

            XmlSignature.Sign(ref xmlDoc, certificate, xmlDoc.DocumentElement, "", true);

            var stringWriter  = new StringWriter();
            var xmlTextWriter = XmlWriter.Create(stringWriter);

            xmlDoc.WriteTo(xmlTextWriter);
            xmlTextWriter.Flush();
            xml = stringWriter.GetStringBuilder().ToString();

            return(xml);
        }
        private string getSignerDescription(XmlSignature signature, ValidationResults vr)
        {
            var text = new StringBuilder();

            text.Append(getCertificateDescription(signature.SigningCertificate));
            if (signature.SigningTime != null)
            {
                text.AppendFormat(" at {0:g}", signature.SigningTime.Value.LocalDateTime);
            }
            text.AppendFormat(" of {0}", signature.SignedEntityType);
            if (signature.SignedEntityType == XmlSignedEntityTypes.XmlElement)
            {
                text.AppendFormat(" {0}", signature.SignedElement.Name);
            }
            if (vr.IsValid)
            {
                text.AppendFormat(" - Valid");
            }
            else
            {
                text.AppendFormat(" - INVALID");
            }
            return(text.ToString());
        }