Пример #1
0
        private void bulkTestWithKeyInfoID(CertificateX509 certificate, PrivateKeyManager key, string pathSigned)
        {
            XmlDSigSigner signer       = new XmlDSigSigner();
            string        pathSignedID = pathSigned + "_id";

            for (int c = 0; c < arrayCanonicalization.Length; c++)
            {
                /**** TEST FILES ****/
                optionsID.DSigSignatureType = dSigType;
                optionsID.Canonicalization  = arrayCanonicalization[c];

                optionsID.XmlSchemaPath = xmlIDSchemaPath;
                bool signedFile = signer.DoSignFileElement(xmlUnsignedIDPathFile, id, key, certificate,
                                                           Path.Combine(xmlSignedPathRoot, pathSignedID + ".xml"), optionsID);
                Assert.IsTrue(signedFile);
                True(signedFile, signer);

                bool verifyFile = false;
                optionsID.XmlSchemaPath = "";
                KeyInfoType keyInfo = KeyInfoTypeUtils.getKeyInfoType(optionsID.KeyInfoType, error);
                if (keyInfo != KeyInfoType.NONE)
                {
                    verifyFile = signer.DoVerifyFile(Path.Combine(xmlSignedPathRoot, pathSignedID + ".xml"), optionsID);
                }
                else
                {
                    verifyFile = signer.DoVerifyFileWithCert(Path.Combine(xmlSignedPathRoot, pathSignedID + ".xml"), certificate,
                                                             optionsID);
                }
                True(verifyFile, signer);

                /**** TEST STRINGS ****/
                optionsID.XmlSchemaPath = xmlIDSchemaPath;
                string signedString     = signer.DoSignElement(xmlUnsignedID, id, key, certificate, optionsID);
                bool   resultSignString = false;

                optionsID.XmlSchemaPath = "";
                if (keyInfo != KeyInfoType.NONE)
                {
                    resultSignString = signer.DoVerify(signedString, optionsID);
                }
                else
                {
                    resultSignString = signer.DoVerifyWithCert(signedString, certificate, optionsID);
                }
                Assert.IsTrue(resultSignString);
                True(resultSignString, signer);
            }
        }
Пример #2
0
        private void bulkTestWithKeyInfoXPath(CertificateX509 certificate, PrivateKeyManager key, string pathSigned)
        {
#if NETCORE
            //******Net Core no tiene habilitado usar la transform xpath******//
            Assert.IsTrue(true);
#else
            XmlDSigSigner signer = new XmlDSigSigner();

            string pathSignedXPath = pathSigned + "_xPAth";
            for (int c = 0; c < arrayCanonicalization.Length; c++)
            {
                /**** TEST FILES ****/
                optionsXPath.DSigSignatureType = dSigType;
                optionsXPath.Canonicalization  = arrayCanonicalization[c];
                bool signedFile = signer.DoSignFileElement(xmlUnsignedXPathFile, xPath, key, certificate,
                                                           Path.Combine(xmlSignedPathRoot, pathSignedXPath + ".xml"), optionsXPath);
                Assert.IsTrue(signedFile);
                True(signedFile, signer);

                bool        verifyFile = false;
                KeyInfoType keyInfo    = KeyInfoTypeUtils.getKeyInfoType(optionsXPath.KeyInfoType, error);
                if (keyInfo != KeyInfoType.NONE)
                {
                    verifyFile = signer.DoVerifyFile(Path.Combine(xmlSignedPathRoot, pathSignedXPath + ".xml"), optionsXPath);
                }
                else
                {
                    verifyFile = signer.DoVerifyFileWithCert(Path.Combine(xmlSignedPathRoot, pathSignedXPath + ".xml"), certificate,
                                                             optionsXPath);
                }
                //True(verifyFile, signer);

                /**** TEST STRINGS ****/

                string signedString     = signer.DoSignElement(xmlUnsignedXPath, xPath, key, certificate, optionsXPath);
                bool   resultSignString = false;
                if (keyInfo != KeyInfoType.NONE)
                {
                    resultSignString = signer.DoVerify(signedString, optionsXPath);
                }
                else
                {
                    resultSignString = signer.DoVerifyWithCert(signedString, certificate, optionsXPath);
                }
                //True(resultSignString, signer);
            }
#endif
        }