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


Java Canonicalizer.getInstance方法代码示例

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


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

示例1: 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

示例2: 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

示例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 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

示例4: 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

示例5: 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

示例6: testTranslationFromUTF16toUTF8

import org.apache.xml.security.c14n.Canonicalizer; //导入方法依赖的package包/类
/**
 * The XPath data model represents data using UCS characters.
 * Implementations MUST use XML processors that support UTF-8 and UTF-16
 * and translate to the UCS character domain. For UTF-16, the leading byte
 * order mark is treated as an artifact of encoding and stripped from the
 * UCS character data (subsequent zero width non-breaking spaces appearing
 * within the UTF-16 data are not removed) [UTF-16, Section 3.2]. Support
 * for ISO-8859-1 encoding is RECOMMENDED, and all other character encodings
 * are OPTIONAL.
 *
 * @throws CanonicalizationException
 * @throws FileNotFoundException
 * @throws IOException
 * @throws InvalidCanonicalizerException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws TransformerException
 */
@org.junit.Test
public void testTranslationFromUTF16toUTF8()
    throws IOException, FileNotFoundException, SAXException,
    ParserConfigurationException, CanonicalizationException,
    InvalidCanonicalizerException, TransformerException {
    String val =
        "<UTF16>The german &amp;auml (which is Unicode &amp;#xE4;):  &quot;&#xE4;&quot;</UTF16>";
    byte utf16[] = convertToUTF16(val.getBytes());
    Canonicalizer c14n =
        Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
    byte c14nBytes[] = c14n.canonicalize(utf16);
    org.xml.sax.EntityResolver resolver = new TestVectorResolver();
    InputStream refStream =
        resolver.resolveEntity(
            null, prefix + "/in/testTranslationFromUTF16toUTF8.xml").getByteStream();
    byte refBytes[] = JavaUtils.getBytesFromStream(refStream);
    boolean equal = java.security.MessageDigest.isEqual(refBytes, c14nBytes);

    assertTrue("Parser does not translate to UCS character domain", equal);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:39,代码来源:Canonicalizer20010315Test.java

示例7: testC14n11Base

import org.apache.xml.security.c14n.Canonicalizer; //导入方法依赖的package包/类
@org.junit.Test
public void testC14n11Base() throws Exception {
    DocumentBuilder documentBuilder = XMLUtils.createDocumentBuilder(true);

    documentBuilder.setErrorHandler(new org.apache.xml.security.utils.IgnoreAllErrorHandler());
    byte inputBytes[] = input.getBytes();
    Document doc =
        documentBuilder.parse(new ByteArrayInputStream(inputBytes));

    Canonicalizer c14n =
        Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N11_OMIT_COMMENTS);

    XPathFactory xpf = XPathFactory.newInstance();
    XPath xPath = xpf.newXPath();
    xPath.setNamespaceContext(new DSNamespaceContext());

    Node signedInfo =
        (Node) xPath.evaluate("//ds:SignedInfo[1]", doc, XPathConstants.NODE);
    byte[] output = c14n.canonicalizeSubtree(signedInfo);

    assertEquals( new String(output, "UTF-8"), expectedResult);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:23,代码来源:Santuario273Test.java

示例8: main

import org.apache.xml.security.c14n.Canonicalizer; //导入方法依赖的package包/类
/**
 * Method main
 *
 * @param args
 * @throws Exception
 */
public static void main(String args[]) throws Exception {
    org.apache.xml.security.Init.init();

    DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();

    dfactory.setNamespaceAware(true);
    dfactory.setValidating(true);

    DocumentBuilder documentBuilder = dfactory.newDocumentBuilder();

    // this is to throw away all validation warnings
    documentBuilder.setErrorHandler(new org.apache.xml.security.utils.IgnoreAllErrorHandler());

    byte inputBytes[] = input.getBytes();
    Document doc =
        documentBuilder.parse(new ByteArrayInputStream(inputBytes));

    // after playing around, we have our document now
    Canonicalizer c14n = Canonicalizer.getInstance(
        "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments");
    byte outputBytes[] = c14n.canonicalizeSubtree(doc);

    System.out.println(new String(outputBytes));
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:31,代码来源:CanonDirect.java

示例9: getOneOriginalDocumentFromEnvelopedSignature

import org.apache.xml.security.c14n.Canonicalizer; //导入方法依赖的package包/类
@Test
public final void getOneOriginalDocumentFromEnvelopedSignature() throws Exception {
	DSSDocument document = new FileDocument("src/test/resources/sample.xml");

	XAdESSignatureParameters signatureParameters = new XAdESSignatureParameters();
	signatureParameters.bLevel().setSigningDate(new Date());
	signatureParameters.setSigningCertificate(getSigningCert());
	signatureParameters.setCertificateChain(getCertificateChain());
	signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPED);
	signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B);

	XAdESService service = new XAdESService(getCompleteCertificateVerifier());

	ToBeSigned dataToSign = service.getDataToSign(document, signatureParameters);
	SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry());
	final DSSDocument signedDocument = service.signDocument(document, signatureParameters, signatureValue);

	SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument);
	validator.setCertificateVerifier(getCompleteCertificateVerifier());
	Reports reports = validator.validateDocument();

	List<DSSDocument> originals = validator.getOriginalDocuments(reports.getDiagnosticData().getFirstSignatureId());
	Assert.assertEquals(1, originals.size());

	DSSDocument original = originals.get(0);

	Canonicalizer canon = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N11_OMIT_COMMENTS);
	String firstDocument = new String(canon.canonicalize(DSSUtils.toByteArray(document)));
	String secondDocument = new String(canon.canonicalize(DSSUtils.toByteArray(original)));
	Assert.assertEquals(firstDocument, secondDocument);
}
 
开发者ID:esig,项目名称:dss,代码行数:32,代码来源:GetOriginalDocumentTest.java

示例10: sign

import org.apache.xml.security.c14n.Canonicalizer; //导入方法依赖的package包/类
/**
 * Canonizes and signs a given input with the authentication private key.
 * of the EBICS user.
 * 
 * <p>The given input to be signed is first Canonized using the 
 * http://www.w3.org/TR/2001/REC-xml-c14n-20010315 algorithm.
 * 
 * <p>The element to be canonized is only the SignedInfo element that should be
 * contained in the request to be signed. Otherwise, a {@link TransformationException}
 * is thrown.
 * 
 * <p> The namespace of the SignedInfo element should be named <b>ds</b> as specified in
 * the EBICS specification for common namespaces nomination.
 * 
 * <p> The signature is ensured using the user X002 private key. This step is done in
 * {@link EbicsUser#authenticate(byte[]) authenticate}.
 * 
 * @param toSign the input to sign
 * @return the signed input
 * @throws EbicsException signature fails.
 */
public byte[] sign(byte[] toSign) throws EbicsException {
  try {
    DocumentBuilderFactory 		factory;
    DocumentBuilder			builder;
    Document				document;
    Node 				node;
    Canonicalizer 			canonicalizer;

    factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setValidating(true);
    builder = factory.newDocumentBuilder();
    builder.setErrorHandler(new IgnoreAllErrorHandler());
    document = builder.parse(new ByteArrayInputStream(toSign));
    node = XPathAPI.selectSingleNode(document, "//ds:SignedInfo");
    canonicalizer = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
    return user.authenticate(canonicalizer.canonicalizeSubtree(node));
  } catch(Exception e) {
    throw new EbicsException(e.getMessage());
  }
}
 
开发者ID:pinaraf,项目名称:ebics,代码行数:43,代码来源:SignedInfo.java

示例11: sign

import org.apache.xml.security.c14n.Canonicalizer; //导入方法依赖的package包/类
/**
 * Canonizes and signs a given input with the authentication private key.
 * of the EBICS user.
 * 
 * <p>The given input to be signed is first Canonized using the 
 * http://www.w3.org/TR/2001/REC-xml-c14n-20010315 algorithm.
 * 
 * <p>The element to be canonized is only the SignedInfo element that should be
 * contained in the request to be signed. Otherwise, a {@link TransformationException}
 * is thrown.
 * 
 * <p> The namespace of the SignedInfo element should be named <b>ds</b> as specified in
 * the EBICS specification for common namespaces nomination.
 * 
 * <p> The signature is ensured using the user X002 private key. This step is done in
 * {@link EbicsUser#authenticate(byte[]) authenticate}.
 * 
 * @param toSign the input to sign
 * @return the signed input
 * @throws EbicsException signature fails.
 */
public byte[] sign(byte[] toSign) throws AxelorException {
  try {
    DocumentBuilderFactory 		factory;
    DocumentBuilder			builder;
    Document				document;
    Node 				node;
    Canonicalizer 			canonicalizer;

    factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setValidating(true);
    builder = factory.newDocumentBuilder();
    builder.setErrorHandler(new IgnoreAllErrorHandler());
    document = builder.parse(new ByteArrayInputStream(toSign));
    node = XPathAPI.selectSingleNode(document, "//ds:SignedInfo");
    canonicalizer = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
    return Beans.get(EbicsUserService.class).authenticate(user, canonicalizer.canonicalizeSubtree(node));
  } catch(Exception e) {
    e.printStackTrace();
    throw new AxelorException(e, IException.CONFIGURATION_ERROR);
  }
}
 
开发者ID:axelor,项目名称:axelor-business-suite,代码行数:44,代码来源:SignedInfo.java

示例12: XMLCipher

import org.apache.xml.security.c14n.Canonicalizer; //导入方法依赖的package包/类
/**
 * Creates a new <code>XMLCipher</code>.
 *
 * @param transformation    the name of the transformation, e.g., 
 *                          <code>XMLCipher.TRIPLEDES</code>. If null the XMLCipher can only 
 *                          be used for decrypt or unwrap operations where the encryption method
 *                          is defined in the <code>EncryptionMethod</code> element.
 * @param provider          the JCE provider that supplies the transformation,
 *                          if null use the default provider.
 * @param canon             the name of the c14n algorithm, if
 *                          <code>null</code> use standard serializer
 * @param digestMethod      An optional digestMethod to use. 
 */
private XMLCipher(
    String transformation, 
    String provider, 
    String canonAlg,
    String digestMethod
) throws XMLEncryptionException {
    if (log.isDebugEnabled()) {
        log.debug("Constructing XMLCipher...");
    }

    factory = new Factory();

    algorithm = transformation;
    requestedJCEProvider = provider;
    digestAlg = digestMethod;

    // Create a canonicalizer - used when serializing DOM to octets
    // prior to encryption (and for the reverse)

    try {
        if (canonAlg == null) {
            // The default is to preserve the physical representation.
            this.canon = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_PHYSICAL);
        } else {
            this.canon = Canonicalizer.getInstance(canonAlg);
        }
    } catch (InvalidCanonicalizerException ice) {
        throw new XMLEncryptionException("empty", ice);
    }

    if (serializer == null) {
        serializer = new DocumentSerializer();
    }
    serializer.setCanonicalizer(this.canon);
    
    if (transformation != null) {
        contextCipher = constructCipher(transformation, digestMethod);
    }
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:53,代码来源:XMLCipher.java

示例13: toString

import org.apache.xml.security.c14n.Canonicalizer; //导入方法依赖的package包/类
private String toString (Node n) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Canonicalizer c14n = Canonicalizer.getInstance
    (Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);

    byte[] serBytes = c14n.canonicalizeSubtree(n);
    baos.write(serBytes);
    baos.close();

    return baos.toString("UTF-8");
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:12,代码来源:XMLCipherTest.java

示例14: testRelativeNSbehaviour

import org.apache.xml.security.c14n.Canonicalizer; //导入方法依赖的package包/类
/**
 * Note: This specification supports the recent XML plenary decision to
 * deprecate relative namespace URIs as follows: implementations of XML
 * canonicalization MUST report an operation failure on documents containing
 * relative namespace URIs. XML canonicalization MUST NOT be implemented
 * with an XML parser that converts relative URIs to absolute URIs.
 *
 * Implementations MUST report an operation failure on documents containing
 * relative namespace URIs.
 *
 * @throws CanonicalizationException
 * @throws FileNotFoundException
 * @throws IOException
 * @throws InvalidCanonicalizerException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws TransformerException
 */
@org.junit.Test
public void testRelativeNSbehaviour()
    throws IOException, FileNotFoundException, SAXException,
    ParserConfigurationException, CanonicalizationException,
    InvalidCanonicalizerException, TransformerException {

    //J-
    String inputStr = ""
        + "<absolute:correct      xmlns:absolute='http://www.absolute.org/#likeVodka'>"
        + "<relative:incorrect    xmlns:relative='../cheating#away'>"
        + "</relative:incorrect>"
        + "</absolute:correct>"
        + "\n"
        + "";
    //J+

    DocumentBuilder db = XMLUtils.createDocumentBuilder(false);
    Document doc = db.parse(new ByteArrayInputStream(inputStr.getBytes()));
    boolean weCatchedTheRelativeNS = false;

    try {
        Canonicalizer c14n =
            Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
        c14n.canonicalizeSubtree(doc);

    } catch (CanonicalizationException cex) {
        // if we reach this point - good.
        log.debug("We catched the C14nEx, that's good: " + cex.getMessage());
        weCatchedTheRelativeNS = true;
    }

    assertTrue("We did not catch the relative namespace", weCatchedTheRelativeNS);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:52,代码来源:Canonicalizer20010315Test.java

示例15: doTestXMLAttributes

import org.apache.xml.security.c14n.Canonicalizer; //导入方法依赖的package包/类
/**
 * Method doTestXMLAttributes
 *
 * @param input
 * @param definedOutput
 * @param writeResultsToFile
 *
 * @throws CanonicalizationException
 * @throws FileNotFoundException
 * @throws IOException
 * @throws InvalidCanonicalizerException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws TransformerException
 * @throws XPathExpressionException
 */
private boolean doTestXMLAttributes(String input, String definedOutput)
    throws IOException, FileNotFoundException, SAXException,
ParserConfigurationException, CanonicalizationException,
InvalidCanonicalizerException, TransformerException, XPathExpressionException {

    DocumentBuilder db = XMLUtils.createDocumentBuilder(true);

    db.setErrorHandler(new IgnoreAllErrorHandler());

    Document doc = db.parse(new ByteArrayInputStream(input.getBytes()));
    Canonicalizer c14nizer =
        Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);

    //XMLUtils.circumventBug2650(doc);

    XPathFactory xpf = XPathFactory.newInstance();
    XPath xPath = xpf.newXPath();
    xPath.setNamespaceContext(new DSNamespaceContext());

    String xpath =
        "(//*[local-name()='included'] | //@*[parent::node()[local-name()='included']])";
    NodeList nodes =
        (NodeList)xPath.evaluate(xpath, doc, XPathConstants.NODESET);

    byte result[] = c14nizer.canonicalizeXPathNodeSet(nodes);
    byte defined[] = definedOutput.getBytes();
    assertEquals(definedOutput, new String(result));
    return java.security.MessageDigest.isEqual(defined, result);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:46,代码来源:Canonicalizer20010315Test.java


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