private KeyInfo createKeyInfo(CertificateX509 certificate, string keyInfoType) { KeyInfo keyInfo = new KeyInfo(); KeyInfoType kinfo = KeyInfoTypeUtils.getKeyInfoType(keyInfoType, this.error); switch (kinfo) { case KeyInfoType.KeyValue: if (SecurityUtils.compareStrings(certificate.getPublicKeyAlgorithm(), "RSA")) { keyInfo.AddClause(new RSAKeyValue((RSA)certificate.getPublicKeyXML())); } else { keyInfo.AddClause(new DSAKeyValue((DSA)certificate.getPublicKeyXML())); } break; case KeyInfoType.X509Certificate: KeyInfoX509Data keyInfoX509Data = new KeyInfoX509Data(); keyInfoX509Data.AddCertificate((X509Certificate)certificate.Cert); keyInfoX509Data.AddSubjectName(certificate.Cert.SubjectName.Name); keyInfoX509Data.AddIssuerSerial(certificate.Cert.IssuerName.Name, certificate.Cert.SerialNumber); keyInfo.AddClause((KeyInfoClause)keyInfoX509Data); break; case KeyInfoType.NONE: keyInfo = null; break; } return(keyInfo); }
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); } }
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 }