当前位置: 首页>>代码示例>>Java>>正文


Java DOMSignContext.putNamespacePrefix方法代码示例

本文整理汇总了Java中javax.xml.crypto.dsig.dom.DOMSignContext.putNamespacePrefix方法的典型用法代码示例。如果您正苦于以下问题:Java DOMSignContext.putNamespacePrefix方法的具体用法?Java DOMSignContext.putNamespacePrefix怎么用?Java DOMSignContext.putNamespacePrefix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.crypto.dsig.dom.DOMSignContext的用法示例。


在下文中一共展示了DOMSignContext.putNamespacePrefix方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createAndConfigureSignContext

import javax.xml.crypto.dsig.dom.DOMSignContext; //导入方法依赖的package包/类
private DOMSignContext createAndConfigureSignContext(Node parent, KeySelector keySelector) {
    DOMSignContext dsc = new DOMSignContext(keySelector, parent);
    // set namespace prefix for "http://www.w3.org/2000/09/xmldsig#" according to best practice described in http://www.w3.org/TR/xmldsig-bestpractices/#signing-xml-without-namespaces
    if (getConfiguration().getPrefixForXmlSignatureNamespace() != null
            && !getConfiguration().getPrefixForXmlSignatureNamespace().isEmpty()) {
        dsc.putNamespacePrefix("http://www.w3.org/2000/09/xmldsig#", getConfiguration().getPrefixForXmlSignatureNamespace());
    }
    dsc.putNamespacePrefix("http://www.w3.org/2001/10/xml-exc-c14n#", "ec");
    setCryptoContextProperties(dsc);
    setUriDereferencerAndBaseUri(dsc);
    return dsc;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:13,代码来源:XmlSignerProcessor.java

示例2: signSignature

import javax.xml.crypto.dsig.dom.DOMSignContext; //导入方法依赖的package包/类
private Element signSignature(String id, Element env, KeyInfoFactory keyInfoFactory, X509Credential credential) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, MarshalException, XMLSignatureException {
	if (endorsingToken == null) return env;
	
	NodeList nl = env.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
	for (int i = 0; i < nl.getLength(); i++) {
		Element e = (Element) nl.item(i);
		if (e.hasAttributeNS(null, "Id")) {
			e.setAttributeNS(WSSecurityConstants.WSU_NS, "Id", e.getAttribute("Id"));
			e.setIdAttributeNS(WSSecurityConstants.WSU_NS, "Id", true);
		}
	}
	env = SAMLUtil.loadElementFromString(XMLHelper.nodeToString(env));
	
	
	DigestMethod digestMethod = xsf.newDigestMethod(DigestMethod.SHA1, null);
	List<Transform> transforms = new ArrayList<Transform>(2);
	transforms.add(xsf.newTransform("http://www.w3.org/2001/10/xml-exc-c14n#",new ExcC14NParameterSpec(Collections.singletonList("xsd"))));


   	List<Reference> refs = new ArrayList<Reference>();
   	Reference r = xsf.newReference("#"+id, digestMethod, transforms, null, null);
   	refs.add(r);
   	
	CanonicalizationMethod canonicalizationMethod = xsf.newCanonicalizationMethod(CanonicalizationMethod.EXCLUSIVE, (C14NMethodParameterSpec) null);
	SignatureMethod signatureMethod = xsf.newSignatureMethod(SignatureMethod.RSA_SHA1, null);
   	SignedInfo signedInfo = xsf.newSignedInfo(canonicalizationMethod, signatureMethod, refs);
   	
   	KeyInfo ki = generateKeyInfo(credential, keyInfoFactory, false);
	XMLSignature signature = xsf.newXMLSignature(signedInfo, ki);

       Node security = env.getElementsByTagNameNS(WSSecurityConstants.WSSE_NS, "Security").item(0);
       
       DOMSignContext signContext = new DOMSignContext(credential.getPrivateKey(), security); 
       signContext.putNamespacePrefix(SAMLConstants.XMLSIG_NS, SAMLConstants.XMLSIG_PREFIX);
       signContext.putNamespacePrefix(SAMLConstants.XMLENC_NS, SAMLConstants.XMLENC_PREFIX);
       
       signature.sign(signContext);
       
       return env;
}
 
开发者ID:amagdenko,项目名称:oiosaml.java,代码行数:41,代码来源:OIOSoapEnvelope.java

示例3: sign

import javax.xml.crypto.dsig.dom.DOMSignContext; //导入方法依赖的package包/类
private void sign(KeyStore keyStore, KeyPair keyPair, String alias, Document document, List<EbMSDataSource> dataSources) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException, KeyException, MarshalException, XMLSignatureException, KeyStoreException
{
	//XMLSignatureFactory signFactory = XMLSignatureFactory.getInstance("DOM");
	XMLSignatureFactory signFactory = XMLSignatureFactory.getInstance();
	DigestMethod sha1DigestMethod = signFactory.newDigestMethod(DigestMethod.SHA1,null);
	
	List<Transform> transforms = new ArrayList<Transform>();
	transforms.add(signFactory.newTransform(Transform.ENVELOPED,(TransformParameterSpec)null));
	Map<String,String> m = new HashMap<String,String>();
	m.put("soap","http://schemas.xmlsoap.org/soap/envelope/");
	transforms.add(signFactory.newTransform(Transform.XPATH,new XPathFilterParameterSpec("not(ancestor-or-self::node()[@soap:actor=\"urn:oasis:names:tc:ebxml-msg:service:nextMSH\"]|ancestor-or-self::node()[@soap:actor=\"http://schemas.xmlsoap.org/soap/actor/next\"])",m)));
	transforms.add(signFactory.newTransform(CanonicalizationMethod.INCLUSIVE,(TransformParameterSpec)null));
	
	List<Reference> references = new ArrayList<Reference>();
	references.add(signFactory.newReference("",sha1DigestMethod,transforms,null,null));
	
	for (EbMSDataSource dataSource : dataSources)
		references.add(signFactory.newReference("cid:" + dataSource.getContentId(),sha1DigestMethod,Collections.emptyList(),null,null,DigestUtils.sha(IOUtils.toByteArray(dataSource.getInputStream()))));
	
	SignedInfo signedInfo = signFactory.newSignedInfo(signFactory.newCanonicalizationMethod(CanonicalizationMethod.INCLUSIVE,(C14NMethodParameterSpec)null),signFactory.newSignatureMethod(SignatureMethod.RSA_SHA1,null),references);
	
	List<XMLStructure> keyInfoElements = new ArrayList<XMLStructure>();
	KeyInfoFactory keyInfoFactory = signFactory.getKeyInfoFactory();
	keyInfoElements.add(keyInfoFactory.newKeyValue(keyPair.getPublic()));
	
	Certificate[] certificates = keyStore.getCertificateChain(alias);
	//keyInfoElements.add(keyInfoFactory.newX509Data(Arrays.asList(certificates)));
	keyInfoElements.add(keyInfoFactory.newX509Data(Collections.singletonList(certificates[0])));
	
	KeyInfo keyInfo = keyInfoFactory.newKeyInfo(keyInfoElements);
	
	XMLSignature signature = signFactory.newXMLSignature(signedInfo,keyInfo);
	
	Element soapHeader = getFirstChildElement(document.getDocumentElement());
	DOMSignContext signContext = new DOMSignContext(keyPair.getPrivate(),soapHeader);
	signContext.putNamespacePrefix(XMLSignature.XMLNS,"ds");
	signature.sign(signContext);
}
 
开发者ID:mprins,项目名称:muleebmsadapter,代码行数:39,代码来源:XMLDSignatureOutInterceptor.java

示例4: signDOM

import javax.xml.crypto.dsig.dom.DOMSignContext; //导入方法依赖的package包/类
public static void signDOM(Node node, PrivateKey privateKey, Certificate origCert) {
    XMLSignatureFactory fac = initXMLSigFactory();
    X509Certificate cert = (X509Certificate) origCert;
    // Create the KeyInfo containing the X509Data.
    KeyInfoFactory kif = fac.getKeyInfoFactory();
    List<Object> x509Content = new ArrayList<Object>();
    x509Content.add(cert.getSubjectX500Principal().getName());
    x509Content.add(cert);
    X509Data xd = kif.newX509Data(x509Content);
    KeyInfo ki = kif.newKeyInfo(Collections.singletonList(xd));

    // Create a DOMSignContext and specify the RSA PrivateKey and
    // location of the resulting XMLSignature's parent element.
    DOMSignContext dsc = new DOMSignContext(privateKey, node);
    dsc.putNamespacePrefix("http://www.w3.org/2000/09/xmldsig#", "ns2");

    // Create the XMLSignature, but don't sign it yet.
    try {
        SignedInfo si = initSignedInfo(fac);
        XMLSignature signature = fac.newXMLSignature(si, ki);

        // Marshal, generate, and sign the enveloped signature.
        signature.sign(dsc);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:apache,项目名称:juddi,代码行数:28,代码来源:TckSigningUtil.java

示例5: signDOM

import javax.xml.crypto.dsig.dom.DOMSignContext; //导入方法依赖的package包/类
private void signDOM(Node node, PrivateKey privateKey, Certificate origCert) {
    XMLSignatureFactory fac = initXMLSigFactory();
    X509Certificate cert = (X509Certificate) origCert;
    // Create the KeyInfo containing the X509Data.
    KeyInfoFactory kif = fac.getKeyInfoFactory();
    List<Object> x509Content = new ArrayList<Object>();
    //x509Content.add(cert.getSubjectX500Principal().getName());
    x509Content.add(cert);
    X509Data xd = kif.newX509Data(x509Content);
    KeyInfo ki = kif.newKeyInfo(Collections.singletonList(xd));

    // Create a DOMSignContext and specify the RSA PrivateKey and
    // location of the resulting XMLSignature's parent element.
    DOMSignContext dsc = new DOMSignContext(privateKey, node);
    dsc.putNamespacePrefix(XML_DIGSIG_NS, "ns2");

    // Create the XMLSignature, but don't sign it yet.
    try {
        SignedInfo si = initSignedInfo(fac);
        XMLSignature signature = fac.newXMLSignature(si, ki);

        // Marshal, generate, and sign the enveloped signature.
        signature.sign(dsc);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:apache,项目名称:juddi,代码行数:28,代码来源:XmlSignatureApplet.java

示例6: signElementByTag

import javax.xml.crypto.dsig.dom.DOMSignContext; //导入方法依赖的package包/类
public void signElementByTag(SOAPMessage soapMessage, String tag) throws Exception {
    SOAPUtility.refreshSoap(soapMessage);

    //Формируем новый документ из части сообщения
    NodeList tagNodeList = soapMessage.getSOAPPart().getElementsByTagName(tag);
    Document newXMLDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    Node copyNode = newXMLDocument.importNode(tagNodeList.item(0), true);
    newXMLDocument.appendChild(copyNode);

    //Подписываемый элемент
    NodeList newNodeList = newXMLDocument.getElementsByTagName(tag);
    Element signedNode = (Element) newNodeList.item(0);

    Provider xmlDSigProvider = new ru.CryptoPro.JCPxml.dsig.internal.dom.XMLDSigRI();

    XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM", xmlDSigProvider);

    List<Transform> transformList = new ArrayList<Transform>();

    Transform transform = fac.newTransform(Transform.ENVELOPED, (XMLStructure) null);
    Transform transformC14N = fac.newTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS, (XMLStructure) null);
    transformList.add(transform);
    transformList.add(transformC14N);

    Reference ref = fac.newReference("", fac.newDigestMethod("http://www.w3.org/2001/04/xmldsig-more#gostr3411", null), transformList, null, null);

    SignedInfo si = fac.newSignedInfo(fac.newCanonicalizationMethod(CanonicalizationMethod.EXCLUSIVE,
            (C14NMethodParameterSpec) null),
            fac.newSignatureMethod("http://www.w3.org/2001/04/xmldsig-more#gostr34102001-gostr3411", null),
            Collections.singletonList(ref));

    KeyInfoFactory kif = fac.getKeyInfoFactory();
    X509Data x509d = kif.newX509Data(Collections.singletonList(cert));
    KeyInfo ki = kif.newKeyInfo(Collections.singletonList(x509d));

    javax.xml.crypto.dsig.XMLSignature sig = fac.newXMLSignature(si, ki);

    DOMSignContext signContext = new DOMSignContext(privateKey, signedNode);
    signContext.putNamespacePrefix(javax.xml.crypto.dsig.XMLSignature.XMLNS, "ds");
    sig.sign(signContext);

    //Заменяем исходный элемент на подписанный
    Document doc = soapMessage.getSOAPPart().getEnvelope().getOwnerDocument();
    Node signedTag = newXMLDocument.getFirstChild();
    Node oldNode = tagNodeList.item(0);
    Node parentNode = oldNode.getParentNode();
    parentNode.removeChild(oldNode);
    Node newNode = doc.importNode(signedTag, true);
    parentNode.appendChild(newNode);

}
 
开发者ID:OlegNyr,项目名称:GisGMP,代码行数:52,代码来源:SOAPXMLSignatureManager.java


注:本文中的javax.xml.crypto.dsig.dom.DOMSignContext.putNamespacePrefix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。