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


Java Canonicalizer类代码示例

本文整理汇总了Java中org.apache.xml.security.c14n.Canonicalizer的典型用法代码示例。如果您正苦于以下问题:Java Canonicalizer类的具体用法?Java Canonicalizer怎么用?Java Canonicalizer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Canonicalizer类属于org.apache.xml.security.c14n包,在下文中一共展示了Canonicalizer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setSignatureRaw

import org.apache.xml.security.c14n.Canonicalizer; //导入依赖的package包/类
private static Signature setSignatureRaw(String signatureAlgorithm, X509Credential cred) throws SSOAgentException {
    Signature signature = (Signature) buildXMLObject(Signature.DEFAULT_ELEMENT_NAME);
    signature.setSigningCredential(cred);
    signature.setSignatureAlgorithm(signatureAlgorithm);
    signature.setCanonicalizationAlgorithm(Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS);

    try {
        KeyInfo keyInfo = (KeyInfo) buildXMLObject(KeyInfo.DEFAULT_ELEMENT_NAME);
        X509Data data = (X509Data) buildXMLObject(X509Data.DEFAULT_ELEMENT_NAME);
        org.opensaml.xml.signature.X509Certificate cert =
                (org.opensaml.xml.signature.X509Certificate) buildXMLObject(org.opensaml.xml.signature.X509Certificate.DEFAULT_ELEMENT_NAME);
        String value =
                org.apache.xml.security.utils.Base64.encode(cred.getEntityCertificate().getEncoded());
        cert.setValue(value);
        data.getX509Certificates().add(cert);
        keyInfo.getX509Datas().add(data);
        signature.setKeyInfo(keyInfo);
        return signature;

    } catch (CertificateEncodingException e) {
        throw new SSOAgentException("Error getting certificate", e);
    }
}
 
开发者ID:wso2-extensions,项目名称:identity-agent-sso,代码行数:24,代码来源:SSOAgentUtils.java

示例2: buildContent

import org.apache.xml.security.c14n.Canonicalizer; //导入依赖的package包/类
protected String buildContent(XdmDocument contentDoc, boolean canonical) throws Exception {
    DocumentImpl contentDocInfo = contentDoc.getUnderlyingNode();
    Source contentSrc;
    XmlEncodeOptions contentEncodeOpts = this.xmlCodec.getDefaultEncodeOptions().clone();

    if (canonical) {
        for (SdcctXpathExecutable canonicalRemoveXpathExec : this.resourceMetadata.getCanonicalRemoveXpathExecutables()) {
            for (XdmNode canonicalRemoveNode : canonicalRemoveXpathExec.load(new DynamicXpathOptionsImpl().setContextItem(contentDocInfo))
                .evaluateNodes()) {
                ((MutableNodeInfo) canonicalRemoveNode.getUnderlyingNode()).delete();
            }
        }

        contentEncodeOpts.getParseOptions().setStripSpace(Whitespace.ALL);

        contentSrc = new ByteArraySource(Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N11_OMIT_COMMENTS)
            .canonicalizeSubtree(NodeOverNodeInfo.wrap(contentDoc.getUnderlyingNode())), contentDoc.getPublicId(), contentDoc.getSystemId());
    } else {
        contentSrc = contentDoc.getUnderlyingNode();
    }

    return new String(this.xmlCodec.encode(contentSrc, contentEncodeOpts), StandardCharsets.UTF_8);
}
 
开发者ID:esacinc,项目名称:sdcct,代码行数:24,代码来源:AbstractSdcctResourceRegistry.java

示例3: transform

import org.apache.xml.security.c14n.Canonicalizer; //导入依赖的package包/类
@Override
public Data transform(Data data, XMLCryptoContext xc)
    throws TransformException
{
    // ignore comments if dereferencing same-document URI that require
    // you to omit comments, even if the Transform says otherwise -
    // this is to be compliant with section 4.3.3.3 of W3C Rec.
    if (data instanceof DOMSubTreeData) {
        DOMSubTreeData subTree = (DOMSubTreeData)data;
        if (subTree.excludeComments()) {
            try {
                apacheCanonicalizer = Canonicalizer.getInstance
                    (CanonicalizationMethod.EXCLUSIVE);
                boolean secVal = Utils.secureValidation(xc);
                apacheCanonicalizer.setSecureValidation(secVal);
            } catch (InvalidCanonicalizerException ice) {
                throw new TransformException
                    ("Couldn't find Canonicalizer for: " +
                     CanonicalizationMethod.EXCLUSIVE + ": " +
                     ice.getMessage(), ice);
            }
        }
    }

    return canonicalize(data, xc);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:27,代码来源:DOMExcC14NMethod.java

示例4: transform

import org.apache.xml.security.c14n.Canonicalizer; //导入依赖的package包/类
@Override
public Data transform(Data data, XMLCryptoContext xc)
    throws TransformException {

    // ignore comments if dereferencing same-document URI that requires
    // you to omit comments, even if the Transform says otherwise -
    // this is to be compliant with section 4.3.3.3 of W3C Rec.
    if (data instanceof DOMSubTreeData) {
        DOMSubTreeData subTree = (DOMSubTreeData) data;
        if (subTree.excludeComments()) {
            try {
                apacheCanonicalizer = Canonicalizer.getInstance
                    (CanonicalizationMethod.INCLUSIVE);
                boolean secVal = Utils.secureValidation(xc);
                apacheCanonicalizer.setSecureValidation(secVal);
            } catch (InvalidCanonicalizerException ice) {
                throw new TransformException
                    ("Couldn't find Canonicalizer for: " +
                     CanonicalizationMethod.INCLUSIVE + ": " +
                     ice.getMessage(), ice);
            }
        }
    }

    return canonicalize(data, xc);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:27,代码来源:DOMCanonicalXMLC14NMethod.java

示例5: transform

import org.apache.xml.security.c14n.Canonicalizer; //导入依赖的package包/类
@Override
public Data transform(Data data, XMLCryptoContext xc)
    throws TransformException {

    // ignore comments if dereferencing same-document URI that requires
    // you to omit comments, even if the Transform says otherwise -
    // this is to be compliant with section 4.3.3.3 of W3C Rec.
    if (data instanceof DOMSubTreeData) {
        DOMSubTreeData subTree = (DOMSubTreeData) data;
        if (subTree.excludeComments()) {
            try {
                apacheCanonicalizer = Canonicalizer.getInstance(C14N_11);
                boolean secVal = Utils.secureValidation(xc);
                apacheCanonicalizer.setSecureValidation(secVal);
            } catch (InvalidCanonicalizerException ice) {
                throw new TransformException
                    ("Couldn't find Canonicalizer for: " +
                     C14N_11 + ": " + ice.getMessage(), ice);
            }
        }
    }

    return canonicalize(data, xc);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:25,代码来源:DOMCanonicalXMLC14N11Method.java

示例6: getCanonicalizedOctetStream

import org.apache.xml.security.c14n.Canonicalizer; //导入依赖的package包/类
/**
 * Returns getCanonicalizedOctetStream
 *
 * @return the canonicalization result octet stream of <code>SignedInfo</code> element
 * @throws CanonicalizationException
 * @throws InvalidCanonicalizerException
 * @throws XMLSecurityException
 */
public byte[] getCanonicalizedOctetStream()
    throws CanonicalizationException, InvalidCanonicalizerException, XMLSecurityException {
    if (this.c14nizedBytes == null) {
        Canonicalizer c14nizer =
            Canonicalizer.getInstance(this.getCanonicalizationMethodURI());
        c14nizer.setSecureValidation(isSecureValidation());

        String inclusiveNamespaces = this.getInclusiveNamespaces();
        if (inclusiveNamespaces == null) {
            this.c14nizedBytes = c14nizer.canonicalizeSubtree(getElement());
        } else {
            this.c14nizedBytes = c14nizer.canonicalizeSubtree(getElement(), inclusiveNamespaces);
        }
    }

    // make defensive copy
    return this.c14nizedBytes.clone();
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:27,代码来源:SignedInfo.java

示例7: signInOctetStream

import org.apache.xml.security.c14n.Canonicalizer; //导入依赖的package包/类
/**
 * Output the C14n stream to the given OutputStream.
 * @param os
 * @throws CanonicalizationException
 * @throws InvalidCanonicalizerException
 * @throws XMLSecurityException
 */
public void signInOctetStream(OutputStream os)
    throws CanonicalizationException, InvalidCanonicalizerException, XMLSecurityException {
    if (this.c14nizedBytes == null) {
        Canonicalizer c14nizer =
            Canonicalizer.getInstance(this.getCanonicalizationMethodURI());
        c14nizer.setSecureValidation(isSecureValidation());
        c14nizer.setWriter(os);
        String inclusiveNamespaces = this.getInclusiveNamespaces();

        if (inclusiveNamespaces == null) {
            c14nizer.canonicalizeSubtree(getElement());
        } else {
            c14nizer.canonicalizeSubtree(getElement(), inclusiveNamespaces);
        }
    } else {
        try {
            os.write(this.c14nizedBytes);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:30,代码来源:SignedInfo.java

示例8: test_generate_hmac_sha1_40

import org.apache.xml.security.c14n.Canonicalizer; //导入依赖的package包/类
@org.junit.Test
public void test_generate_hmac_sha1_40() throws Exception {
    Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
    XMLSignature sig =
        new XMLSignature(
            doc, null, XMLSignature.ALGO_ID_MAC_HMAC_SHA1,
            40, Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS
        );
    try {
        sig.sign(getSecretKey("secret".getBytes("ASCII")));
        fail("Expected HMACOutputLength Exception");
    } catch (XMLSignatureException xse) {
        // System.out.println(xse.getMessage());
        if (!xse.getMsgID().equals("algorithms.HMACOutputLengthMin")) {
            fail(xse.getMessage());
        }
    }
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:19,代码来源:HMACOutputLengthTest.java

示例9: test31withCommentsSubtree

import org.apache.xml.security.c14n.Canonicalizer; //导入依赖的package包/类
/**
 * 3.1 PIs, Comments, and Outside of Document Element
 *
 * @throws CanonicalizationException
 * @throws FileNotFoundException
 * @throws IOException
 * @throws InvalidCanonicalizerException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws TransformerException
 * @throws XPathExpressionException
 */
@org.junit.Test
public void test31withCommentsSubtree()
    throws IOException, FileNotFoundException, SAXException,
    ParserConfigurationException, CanonicalizationException,
    InvalidCanonicalizerException, TransformerException, XPathExpressionException {
    String descri =
        "3.1: PIs, Comments, and Outside of Document Element. (commented)";

    String fileIn = prefix + "in/31_input.xml";
    String fileRef = prefix + "in/31_c14n-comments.xml";
    String fileOut = prefix + "out/xpath_31_output-comments.xml";
    String c14nURI = Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS;
    boolean validating = true;
    String xpath = null;

    assertTrue(descri,
               c14nAndCompare(fileIn, fileRef, fileOut, c14nURI, validating, xpath));
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:31,代码来源:Canonicalizer20010315Test.java

示例10: test31withCommentsSubset

import org.apache.xml.security.c14n.Canonicalizer; //导入依赖的package包/类
/**
 * 3.1 PIs, Comments, and Outside of Document Element
 *
 * @throws CanonicalizationException
 * @throws FileNotFoundException
 * @throws IOException
 * @throws InvalidCanonicalizerException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws TransformerException
 * @throws XPathExpressionException
 */
@org.junit.Test
public void test31withCommentsSubset()
    throws IOException, FileNotFoundException, SAXException,
    ParserConfigurationException, CanonicalizationException,
    InvalidCanonicalizerException, TransformerException, XPathExpressionException {
    String descri =
        "3.1: PIs, Comments, and Outside of Document Element. (commented)";

    String fileIn = prefix + "in/31_input.xml";
    String fileRef = prefix + "in/31_c14n-comments.xml";
    String fileOut = prefix + "out/xpath_31_output-comments.xml";
    String c14nURI = Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS;
    boolean validating = true;
    String xpath = Canonicalizer.XPATH_C14N_WITH_COMMENTS_SINGLE_NODE;

    assertTrue(descri,
               c14nAndCompare(fileIn, fileRef, fileOut, c14nURI, validating, xpath));
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:31,代码来源:Canonicalizer20010315Test.java

示例11: test31subtree

import org.apache.xml.security.c14n.Canonicalizer; //导入依赖的package包/类
/**
 * 3.1 PIs, Comments, and Outside of Document Element
 *
 * @throws CanonicalizationException
 * @throws FileNotFoundException
 * @throws IOException
 * @throws InvalidCanonicalizerException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @see <A HREF="http://www.w3.org/TR/2001/PR-xml-c14n-20010119#Example-OutsideDoc">the example from the spec</A>
 * @throws TransformerException
 * @throws XPathExpressionException
 */
@org.junit.Test
public void test31subtree()
    throws IOException, FileNotFoundException, SAXException,
    ParserConfigurationException, CanonicalizationException,
    InvalidCanonicalizerException, TransformerException, XPathExpressionException {
    String descri =
        "3.1: PIs, Comments, and Outside of Document Element. (uncommented)";
    String fileIn = prefix + "in/31_input.xml";
    String fileRef = prefix + "in/31_c14n.xml";
    String fileOut = prefix + "out/xpath_31_output.xml";
    String c14nURI = Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS;
    boolean validating = true;
    String xpath = null;

    assertTrue(descri,
               c14nAndCompare(fileIn, fileRef, fileOut, c14nURI, validating, xpath));
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:31,代码来源:Canonicalizer20010315Test.java

示例12: test31subset

import org.apache.xml.security.c14n.Canonicalizer; //导入依赖的package包/类
/**
 * 3.1 PIs, Comments, and Outside of Document Element
 *
 * @throws CanonicalizationException
 * @throws FileNotFoundException
 * @throws IOException
 * @throws InvalidCanonicalizerException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @see <A HREF="http://www.w3.org/TR/2001/PR-xml-c14n-20010119#Example-OutsideDoc">the example from the spec</A>
 * @throws TransformerException
 * @throws XPathExpressionException
 */
@org.junit.Test
public void test31subset()
    throws IOException, FileNotFoundException, SAXException,
    ParserConfigurationException, CanonicalizationException,
    InvalidCanonicalizerException, TransformerException, XPathExpressionException {

    String descri =
        "3.1: PIs, Comments, and Outside of Document Element. (uncommented)";
    String fileIn = prefix + "in/31_input.xml";
    String fileRef = prefix + "in/31_c14n.xml";
    String fileOut = prefix + "out/xpath_31_output.xml";
    String c14nURI = Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS;
    boolean validating = true;
    String xpath = Canonicalizer.XPATH_C14N_WITH_COMMENTS_SINGLE_NODE;

    assertTrue(descri,
               c14nAndCompare(fileIn, fileRef, fileOut, c14nURI, validating, xpath));
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:32,代码来源:Canonicalizer20010315Test.java

示例13: test32subtree

import org.apache.xml.security.c14n.Canonicalizer; //导入依赖的package包/类
/**
 * 3.2 Whitespace in Document Content
 *
 * @throws CanonicalizationException
 * @throws FileNotFoundException
 * @throws IOException
 * @throws InvalidCanonicalizerException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @see <A HREF="http://www.w3.org/TR/2001/PR-xml-c14n-20010119#Example-WhitespaceInContent">the example from the spec</A>
 * @throws TransformerException
 * @throws XPathExpressionException
 */
@org.junit.Test
public void test32subtree()
    throws IOException, FileNotFoundException, SAXException,
    ParserConfigurationException, CanonicalizationException,
    InvalidCanonicalizerException, TransformerException, XPathExpressionException {
    String descri = "3.2 Whitespace in Document Content. (uncommented)";
    String fileIn = prefix + "in/32_input.xml";
    String fileRef = prefix + "in/32_c14n.xml";
    String fileOut = prefix + "out/xpath_32_output.xml";
    String c14nURI = Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS;
    boolean validating = true;
    String xpath = null;

    assertTrue(descri,
               c14nAndCompare(fileIn, fileRef, fileOut, c14nURI, validating, xpath));
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:30,代码来源:Canonicalizer20010315Test.java

示例14: test32subset

import org.apache.xml.security.c14n.Canonicalizer; //导入依赖的package包/类
/**
 * 3.2 Whitespace in Document Content
 *
 * @throws CanonicalizationException
 * @throws FileNotFoundException
 * @throws IOException
 * @throws InvalidCanonicalizerException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @see <A HREF="http://www.w3.org/TR/2001/PR-xml-c14n-20010119#Example-WhitespaceInContent">the example from the spec</A>
 * @throws TransformerException
 * @throws XPathExpressionException
 */
@org.junit.Test
public void test32subset()
    throws IOException, FileNotFoundException, SAXException,
    ParserConfigurationException, CanonicalizationException,
    InvalidCanonicalizerException, TransformerException, XPathExpressionException {
    String descri = "3.2 Whitespace in Document Content. (uncommented)";
    String fileIn = prefix + "in/32_input.xml";
    String fileRef = prefix + "in/32_c14n.xml";
    String fileOut = prefix + "out/xpath_32_output.xml";
    String c14nURI = Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS;
    boolean validating = true;
    String xpath = Canonicalizer.XPATH_C14N_WITH_COMMENTS_SINGLE_NODE;

    assertTrue(descri,
               c14nAndCompare(fileIn, fileRef, fileOut, c14nURI, validating, xpath));
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:30,代码来源:Canonicalizer20010315Test.java

示例15: test33subtree

import org.apache.xml.security.c14n.Canonicalizer; //导入依赖的package包/类
/**
 * 3.3 Start and End Tags
 *
 * @throws CanonicalizationException
 * @throws FileNotFoundException
 * @throws IOException
 * @throws InvalidCanonicalizerException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @see <A HREF="http://www.w3.org/TR/2001/PR-xml-c14n-20010119#Example-SETags">the example from the spec</A>
 * @throws TransformerException
 * @throws XPathExpressionException
 */
@org.junit.Test
public void test33subtree()
    throws IOException, FileNotFoundException, SAXException,
    ParserConfigurationException, CanonicalizationException,
    InvalidCanonicalizerException, TransformerException, XPathExpressionException {
    String descri = "3.3 Start and End Tags. (uncommented)";
    String fileIn = prefix + "in/33_input.xml";
    String fileRef = prefix + "in/33_c14n.xml";
    String fileOut = prefix + "out/xpath_33_output.xml";
    String c14nURI = Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS;
    boolean validating = true;
    String xpath = null;    // Canonicalizer.XPATH_C14N_OMIT_COMMENTS_SINGLE_NODE;

    assertTrue(descri,
               c14nAndCompare(fileIn, fileRef, fileOut, c14nURI, validating, xpath));
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:30,代码来源:Canonicalizer20010315Test.java


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