本文整理汇总了Java中com.sun.org.apache.xml.internal.security.c14n.Canonicalizer.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java Canonicalizer.getInstance方法的具体用法?Java Canonicalizer.getInstance怎么用?Java Canonicalizer.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.org.apache.xml.internal.security.c14n.Canonicalizer
的用法示例。
在下文中一共展示了Canonicalizer.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transform
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer; //导入方法依赖的package包/类
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);
} catch (InvalidCanonicalizerException ice) {
throw new TransformException
("Couldn't find Canonicalizer for: " +
CanonicalizationMethod.EXCLUSIVE + ": " +
ice.getMessage(), ice);
}
}
}
return canonicalize(data, xc);
}
示例2: transform
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer; //导入方法依赖的package包/类
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);
} catch (InvalidCanonicalizerException ice) {
throw new TransformException
("Couldn't find Canonicalizer for: " +
CanonicalizationMethod.INCLUSIVE + ": " +
ice.getMessage(), ice);
}
}
}
return canonicalize(data, xc);
}
示例3: transform
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer; //导入方法依赖的package包/类
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);
} catch (InvalidCanonicalizerException ice) {
throw new TransformException
("Couldn't find Canonicalizer for: " +
C14N_11 + ": " + ice.getMessage(), ice);
}
}
}
return canonicalize(data, xc);
}
示例4: signInOctetStream
import com.sun.org.apache.xml.internal.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.setWriter(os);
String inclusiveNamespaces = this.getInclusiveNamespaces();
if (inclusiveNamespaces == null) {
c14nizer.canonicalizeSubtree(this.constructionElement);
} else {
c14nizer.canonicalizeSubtree(this.constructionElement, inclusiveNamespaces);
}
} else {
try {
os.write(this.c14nizedBytes);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
示例5: transform
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer; //导入方法依赖的package包/类
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);
} catch (InvalidCanonicalizerException ice) {
throw new TransformException
("Couldn't find Canonicalizer for: " +
CanonicalizationMethod.EXCLUSIVE + ": " +
ice.getMessage(), ice);
}
}
}
return canonicalize(data, xc);
}
示例6: getCanonicalizedOctetStream
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer; //导入方法依赖的package包/类
/**
* Returns getCanonicalizedOctetStream
*
* @return the canonicalization result octedt stream of <code>SignedInfo</code> element
* @throws CanonicalizationException
* @throws InvalidCanonicalizerException
* @throws XMLSecurityException
*/
public byte[] getCanonicalizedOctetStream()
throws CanonicalizationException, InvalidCanonicalizerException,
XMLSecurityException {
if ((this._c14nizedBytes == null)
/*&& (this._state == ElementProxy.MODE_SIGN)*/) {
Canonicalizer c14nizer =
Canonicalizer.getInstance(this.getCanonicalizationMethodURI());
this._c14nizedBytes =
c14nizer.canonicalizeSubtree(this._constructionElement);
}
// make defensive copy
byte[] output = new byte[this._c14nizedBytes.length];
System.arraycopy(this._c14nizedBytes, 0, output, 0, output.length);
return output;
}
示例7: signInOctectStream
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer; //导入方法依赖的package包/类
/**
* Output the C14n stream to the give outputstream.
* @param os
* @throws CanonicalizationException
* @throws InvalidCanonicalizerException
* @throws XMLSecurityException
*/
public void signInOctectStream(OutputStream os)
throws CanonicalizationException, InvalidCanonicalizerException,
XMLSecurityException {
if ((this._c14nizedBytes == null)) {
Canonicalizer c14nizer =
Canonicalizer.getInstance(this.getCanonicalizationMethodURI());
c14nizer.setWriter(os);
String inclusiveNamespaces = this.getInclusiveNamespaces();
if(inclusiveNamespaces == null)
c14nizer.canonicalizeSubtree(this._constructionElement);
else
c14nizer.canonicalizeSubtree(this._constructionElement, inclusiveNamespaces);
} else {
try {
os.write(this._c14nizedBytes);
} catch (IOException e) {
throw new RuntimeException(""+e);
}
}
}
示例8: getCanonicalizedOctetStream
import com.sun.org.apache.xml.internal.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());
this.c14nizedBytes =
c14nizer.canonicalizeSubtree(this.constructionElement);
}
// make defensive copy
return this.c14nizedBytes.clone();
}
示例9: XMLCipher
import com.sun.org.apache.xml.internal.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.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "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);
}
}
示例10: getWrapperTags
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer; //导入方法依赖的package包/类
protected byte[][] getWrapperTags() throws Exception {
String ns = myThreadSafeData.getWrapperNS(), prefix = myThreadSafeData.getWrapperPrefix(), xsi = null, xsiSchemaLoc = null;
boolean isXsi = myThreadSafeData.isWrapperXsi(), isXsiSchemaLoc = myThreadSafeData.isWrapperXsiSchemaLoc();
if (isXsi) {
xsi = myThreadSafeData.getWrapperXsi();
if (isXsiSchemaLoc)
xsiSchemaLoc = myThreadSafeData.getWrapperXsiSchemaLoc();
}
if ("".equals(ns) && !"".equals(prefix))
throw new Exception("non-empty wrapperPrefix not allower for empty wrapperNS");
byte[][] tags = new byte[2][];
String startTag, endTag;
Canonicalizer canonicalizer = Canonicalizer.getInstance(CanonicalizationMethod.INCLUSIVE);
if ("".equals(prefix)) {
//<Wrapper xmlns="urn:xmpp:xml-element" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:xmpp:xml-element FATCA-IDES-FileWrapper-1.1.xsd">
startTag = "<Wrapper xmlns=\"" + ns + "\"" + (xsi==null?"":" " + xsi + (xsiSchemaLoc==null?"":" " + xsiSchemaLoc)) + ">";
endTag = "</Wrapper>";
} else {
//<xyz:Wrapper xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xyz="urn:xmpp:xml-element" xsi:schemaLocation="urn:xmpp:xml-element FATCA-IDES-FileWrapper-1.1.xsd">
startTag = "<" + prefix + ":Wrapper xmlns" + ":" + prefix + "=\"" + ns + "\"" +
(xsi==null?"":" " + xsi + (xsiSchemaLoc==null?"":" " + xsiSchemaLoc)) + ">";
endTag = "</" + prefix + ":Wrapper>";
}
startTag = new String(canonicalizer.canonicalize((startTag + endTag).getBytes()));
startTag = startTag.replaceFirst(endTag, "");
tags[0] = startTag.getBytes();
tags[1] = endTag.getBytes();
return tags;
}
示例11: getProviderInstance
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer; //导入方法依赖的package包/类
/**
* Returns an <code>XMLCipher</code> that implements no specific
* transformation, and can therefore only be used for decrypt or
* unwrap operations where the encryption method is defined in the
* <code>EncryptionMethod</code> element.
*
* Allows the caller to specify a provider that will be used for
* cryptographic operations.
*
* @param provider the JCE provider that supplies the cryptographic
* needs.
* @return the XMLCipher
* @throws XMLEncryptionException
*/
public static XMLCipher getProviderInstance(String provider)
throws XMLEncryptionException {
// sanity checks
logger.log(java.util.logging.Level.FINE, "Getting XMLCipher, provider but no transformation");
if(null == provider)
logger.log(java.util.logging.Level.SEVERE, "Provider unexpectedly null..");
if("" == provider)
logger.log(java.util.logging.Level.SEVERE, "Provider's value unexpectedly not specified...");
XMLCipher instance = new XMLCipher();
instance._algorithm = null;
instance._requestedJCEProvider = provider;
instance._key = null;
instance._kek = null;
instance._contextCipher = null;
try {
instance._canon = Canonicalizer.getInstance
(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS);
} catch (InvalidCanonicalizerException ice) {
throw new XMLEncryptionException("empty", ice);
}
return (instance);
}
示例12: getInstance
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer; //导入方法依赖的package包/类
public static XMLCipher getInstance(String transformation,Cipher cipher) throws XMLEncryptionException {
// sanity checks
logger.log(java.util.logging.Level.FINE, "Getting XMLCipher...");
if (null == transformation)
logger.log(java.util.logging.Level.SEVERE, "Transformation unexpectedly null...");
if(!isValidEncryptionAlgorithm(transformation))
logger.log(java.util.logging.Level.WARNING, "Algorithm non-standard, expected one of " + ENC_ALGORITHMS);
XMLCipher instance = new XMLCipher();
instance._algorithm = transformation;
instance._key = null;
instance._kek = null;
/* Create a canonicaliser - used when serialising DOM to octets
* prior to encryption (and for the reverse) */
try {
instance._canon = Canonicalizer.getInstance
(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS);
} catch (InvalidCanonicalizerException ice) {
throw new XMLEncryptionException("empty", ice);
}
String jceAlgorithm = JCEMapper.translateURItoJCEID(transformation);
try {
instance._contextCipher = cipher;
//Cipher.getInstance(jceAlgorithm);
logger.log(java.util.logging.Level.FINE, "cihper.algoritm = " +
instance._contextCipher.getAlgorithm());
}catch(Exception ex) {
throw new XMLEncryptionException("empty", ex);
}
return (instance);
}
示例13: assertXMLEquals
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer; //导入方法依赖的package包/类
private void assertXMLEquals(String expected, String actual)
throws InvalidCanonicalizerException, ParserConfigurationException,
SAXException, CanonicalizationException, IOException {
Init.init();
Canonicalizer canon = Canonicalizer
.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
String expectedCanonicalized = new String(canon.canonicalize(expected
.getBytes()));
String actualCanonicalized = new String(canon.canonicalize(actual
.getBytes()));
assertEquals(expectedCanonicalized, actualCanonicalized);
}
示例14: canonicalize
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer; //导入方法依赖的package包/类
public Data canonicalize(Data data, XMLCryptoContext xc, OutputStream os)
throws TransformException
{
if (apacheCanonicalizer == null) {
try {
apacheCanonicalizer = Canonicalizer.getInstance(getAlgorithm());
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Created canonicalizer for algorithm: " + getAlgorithm());
}
} catch (InvalidCanonicalizerException ice) {
throw new TransformException
("Couldn't find Canonicalizer for: " + getAlgorithm() +
": " + ice.getMessage(), ice);
}
}
if (os != null) {
apacheCanonicalizer.setWriter(os);
} else {
apacheCanonicalizer.setWriter(new ByteArrayOutputStream());
}
try {
Set<Node> nodeSet = null;
if (data instanceof ApacheData) {
XMLSignatureInput in =
((ApacheData)data).getXMLSignatureInput();
if (in.isElement()) {
if (inclusiveNamespaces != null) {
return new OctetStreamData(new ByteArrayInputStream
(apacheCanonicalizer.canonicalizeSubtree
(in.getSubNode(), inclusiveNamespaces)));
} else {
return new OctetStreamData(new ByteArrayInputStream
(apacheCanonicalizer.canonicalizeSubtree
(in.getSubNode())));
}
} else if (in.isNodeSet()) {
nodeSet = in.getNodeSet();
} else {
return new OctetStreamData(new ByteArrayInputStream(
apacheCanonicalizer.canonicalize(
Utils.readBytesFromStream(in.getOctetStream()))));
}
} else if (data instanceof DOMSubTreeData) {
DOMSubTreeData subTree = (DOMSubTreeData)data;
if (inclusiveNamespaces != null) {
return new OctetStreamData(new ByteArrayInputStream
(apacheCanonicalizer.canonicalizeSubtree
(subTree.getRoot(), inclusiveNamespaces)));
} else {
return new OctetStreamData(new ByteArrayInputStream
(apacheCanonicalizer.canonicalizeSubtree
(subTree.getRoot())));
}
} else if (data instanceof NodeSetData) {
NodeSetData<?> nsd = (NodeSetData<?>)data;
// convert Iterator to Set<Node>
nodeSet = Utils.toNodeSet(nsd.iterator());
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Canonicalizing " + nodeSet.size() + " nodes");
}
} else {
return new OctetStreamData(new ByteArrayInputStream(
apacheCanonicalizer.canonicalize(
Utils.readBytesFromStream(
((OctetStreamData)data).getOctetStream()))));
}
if (inclusiveNamespaces != null) {
return new OctetStreamData(new ByteArrayInputStream(
apacheCanonicalizer.canonicalizeXPathNodeSet
(nodeSet, inclusiveNamespaces)));
} else {
return new OctetStreamData(new ByteArrayInputStream(
apacheCanonicalizer.canonicalizeXPathNodeSet(nodeSet)));
}
} catch (Exception e) {
throw new TransformException(e);
}
}
示例15: getInstance
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer; //导入方法依赖的package包/类
/**
* Returns an <code>XMLCipher</code> that implements the specified
* transformation, operates on the specified context document and serializes
* the document with the specified canonicalization algorithm before it
* encrypts the document.
* <p>
*
* @param transformation the name of the transformation, e.g.,
* <code>XMLCipher.TRIPLEDES</code> which is
* shorthand for
* "http://www.w3.org/2001/04/xmlenc#tripledes-cbc"
* @param canon the name of the c14n algorithm, if
* <code>null</code> use standard serializer
* @return
* @throws XMLEncryptionException
*/
public static XMLCipher getInstance(String transformation, String canon)
throws XMLEncryptionException {
XMLCipher instance = XMLCipher.getInstance(transformation);
if (canon != null) {
try {
instance._canon = Canonicalizer.getInstance(canon);
} catch (InvalidCanonicalizerException ice) {
throw new XMLEncryptionException("empty", ice);
}
}
return instance;
}