本文整理汇总了Java中org.apache.xml.security.utils.XMLUtils类的典型用法代码示例。如果您正苦于以下问题:Java XMLUtils类的具体用法?Java XMLUtils怎么用?Java XMLUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XMLUtils类属于org.apache.xml.security.utils包,在下文中一共展示了XMLUtils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testSHA224
import org.apache.xml.security.utils.XMLUtils; //导入依赖的package包/类
@org.junit.Test
public void testSHA224() throws Exception {
Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
MessageDigestAlgorithm digestAlgorithm =
MessageDigestAlgorithm.getInstance(doc, MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA224);
assertEquals(MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA224, digestAlgorithm.getAlgorithmURI());
byte[] digest = digestAlgorithm.digest("test-string".getBytes());
assertNotNull(digest);
assertTrue(digest.length > 0);
// Now compare against a JDK MessageDigest Object
MessageDigest md = MessageDigest.getInstance("SHA-224");
byte[] digest2 = md.digest("test-string".getBytes());
assertTrue(Arrays.equals(digest, digest2));
}
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:18,代码来源:DigestAlgorithmTest.java
示例2: getNodeSet
import org.apache.xml.security.utils.XMLUtils; //导入依赖的package包/类
private Set<Node> getNodeSet(List<NodeFilter> nodeFilters) {
if (xi.isNeedsToBeExpanded()) {
XMLUtils.circumventBug2650
(XMLUtils.getOwnerDocument(xi.getSubNode()));
}
Set<Node> inputSet = new LinkedHashSet<Node>();
XMLUtils.getSet(xi.getSubNode(), inputSet,
null, !xi.isExcludeComments());
Set<Node> nodeSet = new LinkedHashSet<Node>();
for (Node currentNode : inputSet) {
Iterator<NodeFilter> it = nodeFilters.iterator();
boolean skipNode = false;
while (it.hasNext() && !skipNode) {
NodeFilter nf = it.next();
if (nf.isNodeInclude(currentNode) != 1) {
skipNode = true;
}
}
if (!skipNode) {
nodeSet.add(currentNode);
}
}
return nodeSet;
}
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:26,代码来源:ApacheNodeSetData.java
示例3: testRSA_SHA1
import org.apache.xml.security.utils.XMLUtils; //导入依赖的package包/类
@org.junit.Test
public void testRSA_SHA1() throws Exception {
// Read in plaintext document
InputStream sourceDocument =
this.getClass().getClassLoader().getResourceAsStream(
"ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
DocumentBuilder builder = XMLUtils.createDocumentBuilder(false);
Document document = builder.parse(sourceDocument);
List<String> localNames = new ArrayList<String>();
localNames.add("PaymentInfo");
sign(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1, document, localNames, rsaKeyPair.getPrivate());
// XMLUtils.outputDOM(document, System.out);
verify(document, rsaKeyPair.getPublic(), localNames);
}
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:17,代码来源:PKSignatureAlgorithmTest.java
示例4: testRSA_SHA_384
import org.apache.xml.security.utils.XMLUtils; //导入依赖的package包/类
@org.junit.Test
public void testRSA_SHA_384() throws Exception {
// Read in plaintext document
InputStream sourceDocument =
this.getClass().getClassLoader().getResourceAsStream(
"ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
DocumentBuilder builder = XMLUtils.createDocumentBuilder(false);
Document document = builder.parse(sourceDocument);
List<String> localNames = new ArrayList<String>();
localNames.add("PaymentInfo");
sign(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA384, document, localNames, rsaKeyPair.getPrivate());
// XMLUtils.outputDOM(document, System.out);
verify(document, rsaKeyPair.getPublic(), localNames);
}
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:17,代码来源:PKSignatureAlgorithmTest.java
示例5: getNodeSet
import org.apache.xml.security.utils.XMLUtils; //导入依赖的package包/类
/**
* Returns the node set from input which was specified as the parameter of
* {@link XMLSignatureInput} constructor
* @param circumvent
*
* @return the node set
* @throws SAXException
* @throws IOException
* @throws ParserConfigurationException
* @throws CanonicalizationException
*/
public Set<Node> getNodeSet(boolean circumvent) throws ParserConfigurationException,
IOException, SAXException, CanonicalizationException {
if (inputNodeSet != null) {
return inputNodeSet;
}
if (inputOctetStreamProxy == null && subNode != null) {
if (circumvent) {
XMLUtils.circumventBug2650(XMLUtils.getOwnerDocument(subNode));
}
inputNodeSet = new LinkedHashSet<Node>();
XMLUtils.getSet(subNode, inputNodeSet, excludeNode, excludeComments);
return inputNodeSet;
} else if (isOctetStream()) {
convertToNodes();
Set<Node> result = new LinkedHashSet<Node>();
XMLUtils.getSet(subNode, result, null, false);
return result;
}
throw new RuntimeException("getNodeSet() called but no input data present");
}
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:33,代码来源:XMLSignatureInput.java
示例6: Reference
import org.apache.xml.security.utils.XMLUtils; //导入依赖的package包/类
/**
* Build a {@link Reference} from an {@link Element}
*
* @param element <code>Reference</code> element
* @param baseURI the URI of the resource where the XML instance was stored
* @param manifest is the {@link Manifest} of {@link SignedInfo} in which the Reference occurs.
* @param secureValidation whether secure validation is enabled or not
* We need this because the Manifest has the individual {@link ResourceResolver}s which have
* been set by the user
* @throws XMLSecurityException
*/
protected Reference(Element element, String baseURI, Manifest manifest, boolean secureValidation)
throws XMLSecurityException {
super(element, baseURI);
this.secureValidation = secureValidation;
this.baseURI = baseURI;
Element el = XMLUtils.getNextElement(element.getFirstChild());
if (Constants._TAG_TRANSFORMS.equals(el.getLocalName())
&& Constants.SignatureSpecNS.equals(el.getNamespaceURI())) {
transforms = new Transforms(el, this.baseURI);
transforms.setSecureValidation(secureValidation);
if (secureValidation && transforms.getLength() > MAXIMUM_TRANSFORM_COUNT) {
Object exArgs[] = { transforms.getLength(), MAXIMUM_TRANSFORM_COUNT };
throw new XMLSecurityException("signature.tooManyTransforms", exArgs);
}
el = XMLUtils.getNextElement(el.getNextSibling());
}
digestMethodElem = el;
digestValueElement = XMLUtils.getNextElement(digestMethodElem.getNextSibling());
this.manifest = manifest;
}
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:33,代码来源:Reference.java
示例7: SignedInfo
import org.apache.xml.security.utils.XMLUtils; //导入依赖的package包/类
/**
* Constructor SignedInfo
*
* @param doc <code>SignedInfo</code> is placed in this document
* @param signatureMethodURI URI representation of the Digest and
* Signature algorithm
* @param hMACOutputLength
* @param canonicalizationMethodURI URI representation of the
* Canonicalization method
* @throws XMLSecurityException
*/
public SignedInfo(
Document doc, String signatureMethodURI,
int hMACOutputLength, String canonicalizationMethodURI
) throws XMLSecurityException {
super(doc);
c14nMethod =
XMLUtils.createElementInSignatureSpace(getDocument(), Constants._TAG_CANONICALIZATIONMETHOD);
c14nMethod.setAttributeNS(null, Constants._ATT_ALGORITHM, canonicalizationMethodURI);
appendSelf(c14nMethod);
addReturnToSelf();
if (hMACOutputLength > 0) {
this.signatureAlgorithm =
new SignatureAlgorithm(getDocument(), signatureMethodURI, hMACOutputLength);
} else {
this.signatureAlgorithm = new SignatureAlgorithm(getDocument(), signatureMethodURI);
}
signatureMethod = this.signatureAlgorithm.getElement();
appendSelf(signatureMethod);
addReturnToSelf();
}
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:36,代码来源:SignedInfo.java
示例8: testRSA_SHA256_MGF1
import org.apache.xml.security.utils.XMLUtils; //导入依赖的package包/类
@org.junit.Test
public void testRSA_SHA256_MGF1() throws Exception {
if (!bcInstalled) {
return;
}
// Read in plaintext document
InputStream sourceDocument =
this.getClass().getClassLoader().getResourceAsStream(
"ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
DocumentBuilder builder = XMLUtils.createDocumentBuilder(false);
Document document = builder.parse(sourceDocument);
List<String> localNames = new ArrayList<String>();
localNames.add("PaymentInfo");
sign(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256_MGF1, document, localNames, rsaKeyPair.getPrivate());
// XMLUtils.outputDOM(document, System.out);
verify(document, rsaKeyPair.getPublic(), localNames);
}
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:20,代码来源:PKSignatureAlgorithmTest.java
示例9: engineAddContextToElement
import org.apache.xml.security.utils.XMLUtils; //导入依赖的package包/类
/**
* Method engineAddContextToElement
*
* @param element
*/
public void engineAddContextToElement(Element element) {
if (element == null) {
throw new IllegalArgumentException("null element");
}
if (this.HMACOutputLengthSet) {
Document doc = element.getOwnerDocument();
Element HMElem =
XMLUtils.createElementInSignatureSpace(doc, Constants._TAG_HMACOUTPUTLENGTH);
Text HMText =
doc.createTextNode("" + this.HMACOutputLength);
HMElem.appendChild(HMText);
XMLUtils.addReturnToElement(element);
element.appendChild(HMElem);
XMLUtils.addReturnToElement(element);
}
}
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:24,代码来源:IntegrityHmac.java
示例10: testSHA384
import org.apache.xml.security.utils.XMLUtils; //导入依赖的package包/类
@org.junit.Test
public void testSHA384() throws Exception {
Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
MessageDigestAlgorithm digestAlgorithm =
MessageDigestAlgorithm.getInstance(doc, MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA384);
assertEquals(MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA384, digestAlgorithm.getAlgorithmURI());
byte[] digest = digestAlgorithm.digest("test-string".getBytes());
assertNotNull(digest);
assertTrue(digest.length > 0);
// Now compare against a JDK MessageDigest Object
MessageDigest md = MessageDigest.getInstance("SHA-384");
byte[] digest2 = md.digest("test-string".getBytes());
assertTrue(Arrays.equals(digest, digest2));
}
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:18,代码来源:DigestAlgorithmTest.java
示例11: testRSAOAEP11KW
import org.apache.xml.security.utils.XMLUtils; //导入依赖的package包/类
@org.junit.Test
public void testRSAOAEP11KW() throws Exception {
// Read in plaintext document
InputStream sourceDocument =
this.getClass().getClassLoader().getResourceAsStream(
"ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
DocumentBuilder builder = XMLUtils.createDocumentBuilder(false);
Document document = builder.parse(sourceDocument);
// Set up the Key
KeyGenerator keygen = KeyGenerator.getInstance("DESede");
SecretKey key = keygen.generateKey();
// Set up the Key Wrapping Key
XMLCipher cipher = XMLCipher.getInstance(XMLCipher.RSA_OAEP_11);
cipher.init(XMLCipher.WRAP_MODE, rsaKeyPair.getPublic());
EncryptedKey encryptedKey = cipher.encryptKey(document, key);
List<String> localNames = new ArrayList<String>();
localNames.add("PaymentInfo");
String encryptionAlgorithm = XMLCipher.TRIPLEDES;
encrypt(encryptedKey, encryptionAlgorithm, document, localNames, key);
// Check the CreditCard encrypted ok
NodeList nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
Assert.assertEquals(nodeList.getLength(), 0);
// XMLUtils.outputDOM(document, System.out);
document = decrypt(document, rsaKeyPair.getPrivate());
// Check the CreditCard decrypted ok
nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
Assert.assertEquals(nodeList.getLength(), 1);
}
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:37,代码来源:KeyWrapEncryptionAlgorithmTest.java
示例12: testRSA_SHA512_MGF1
import org.apache.xml.security.utils.XMLUtils; //导入依赖的package包/类
@org.junit.Test
public void testRSA_SHA512_MGF1() throws Exception {
if (!bcInstalled) {
return;
}
// Read in plaintext document
InputStream sourceDocument =
this.getClass().getClassLoader().getResourceAsStream(
"ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
DocumentBuilder builder = XMLUtils.createDocumentBuilder(false);
Document document = builder.parse(sourceDocument);
List<String> localNames = new ArrayList<String>();
localNames.add("PaymentInfo");
sign(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA512_MGF1, document, localNames, rsaKeyPair.getPrivate());
// XMLUtils.outputDOM(document, System.out);
verify(document, rsaKeyPair.getPublic(), localNames);
}
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:20,代码来源:PKSignatureAlgorithmTest.java
示例13: testHMACSHA_384
import org.apache.xml.security.utils.XMLUtils; //导入依赖的package包/类
@org.junit.Test
public void testHMACSHA_384() throws Exception {
// Read in plaintext document
InputStream sourceDocument =
this.getClass().getClassLoader().getResourceAsStream(
"ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
DocumentBuilder builder = XMLUtils.createDocumentBuilder(false);
Document document = builder.parse(sourceDocument);
// Set up the Key
byte[] hmacKey = "secret".getBytes("ASCII");
SecretKey key = new SecretKeySpec(hmacKey, "http://www.w3.org/2001/04/xmldsig-more#hmac-sha384");
List<String> localNames = new ArrayList<String>();
localNames.add("PaymentInfo");
sign("http://www.w3.org/2001/04/xmldsig-more#hmac-sha384", document, localNames, key);
// XMLUtils.outputDOM(document, System.out);
verify(document, key, localNames);
}
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:21,代码来源:HMACSignatureAlgorithmTest.java
示例14: readAndVerifySignature
import org.apache.xml.security.utils.XMLUtils; //导入依赖的package包/类
private boolean readAndVerifySignature(
String directory, String file
) throws Exception {
String basedir = System.getProperty("basedir");
if (basedir != null && !"".equals(basedir)) {
directory = basedir + "/" + directory;
}
File f = new File(directory + "/" + file);
javax.xml.parsers.DocumentBuilder db = XMLUtils.createDocumentBuilder(false, false);
org.w3c.dom.Document doc = db.parse(f);
Element sigElement =
(Element) doc.getElementsByTagNameNS(Constants.SignatureSpecNS,
Constants._TAG_SIGNATURE).item(0);
XMLSignature signature = new XMLSignature(sigElement, f.toURI().toURL().toString());
return signature.checkSignatureValue(signature.getKeyInfo().getPublicKey());
}
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:20,代码来源:WrappingAttackTest.java
示例15: itemEncryptedKey
import org.apache.xml.security.utils.XMLUtils; //导入依赖的package包/类
/**
* Method itemEncryptedKey
*
* @param i
* @return the asked EncryptedKey element, null if the index is too big
* @throws XMLSecurityException
*/
public EncryptedKey itemEncryptedKey(int i) throws XMLSecurityException {
if (encryptedKeys != null) {
return encryptedKeys.get(i);
}
Element e =
XMLUtils.selectXencNode(
getFirstChild(), EncryptionConstants._TAG_ENCRYPTEDKEY, i);
if (e != null) {
XMLCipher cipher = XMLCipher.getInstance();
cipher.init(XMLCipher.UNWRAP_MODE, null);
return cipher.loadEncryptedKey(e);
}
return null;
}
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:23,代码来源:KeyInfo.java
示例16: doDOMSignatureOutbound
import org.apache.xml.security.utils.XMLUtils; //导入依赖的package包/类
protected void doDOMSignatureOutbound(File file, int tagCount) throws Exception {
DocumentBuilder builder = XMLUtils.createDocumentBuilder(false);
Document document = builder.parse(file);
XMLSignature sig = new XMLSignature(document, "", "http://www.w3.org/2000/09/xmldsig#rsa-sha1");
Element root = document.getDocumentElement();
root.insertBefore(sig.getElement(), root.getFirstChild());
Transforms transforms = new Transforms(document);
transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
transforms.addTransform(Transforms.TRANSFORM_C14N_OMIT_COMMENTS);
sig.addDocument("", transforms, "http://www.w3.org/2000/09/xmldsig#sha1");
sig.sign(key);
sig.addKeyInfo(cert);
XMLUtils.outputDOM(document, new BufferedOutputStream(new FileOutputStream(new File(getTmpFilePath(), "signature-dom-" + tagCount + ".xml"))));
}
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:20,代码来源:AbstractPerformanceTest.java
示例17: testRIPEMD160
import org.apache.xml.security.utils.XMLUtils; //导入依赖的package包/类
@org.junit.Test
public void testRIPEMD160() throws Exception {
// This only works with BouncyCastle
if (Security.getProvider("BC") == null) {
return;
}
Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
MessageDigestAlgorithm digestAlgorithm =
MessageDigestAlgorithm.getInstance(doc, MessageDigestAlgorithm.ALGO_ID_DIGEST_RIPEMD160);
assertEquals(MessageDigestAlgorithm.ALGO_ID_DIGEST_RIPEMD160, digestAlgorithm.getAlgorithmURI());
byte[] digest = digestAlgorithm.digest("test-string".getBytes());
assertNotNull(digest);
assertTrue(digest.length > 0);
// Now compare against a JDK MessageDigest Object
MessageDigest md = MessageDigest.getInstance("RIPEMD160");
byte[] digest2 = md.digest("test-string".getBytes());
assertTrue(Arrays.equals(digest, digest2));
}
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:22,代码来源:DigestAlgorithmTest.java
示例18: testECDSA_SHA_256
import org.apache.xml.security.utils.XMLUtils; //导入依赖的package包/类
@org.junit.Test
public void testECDSA_SHA_256() throws Exception {
// Read in plaintext document
InputStream sourceDocument =
this.getClass().getClassLoader().getResourceAsStream(
"ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
DocumentBuilder builder = XMLUtils.createDocumentBuilder(false);
Document document = builder.parse(sourceDocument);
List<String> localNames = new ArrayList<String>();
localNames.add("PaymentInfo");
sign(XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA256, document, localNames, ecKeyPair.getPrivate());
// XMLUtils.outputDOM(document, System.out);
verify(document, ecKeyPair.getPublic(), localNames);
}
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:17,代码来源:PKSignatureAlgorithmTest.java
示例19: testRSA_SHA_224
import org.apache.xml.security.utils.XMLUtils; //导入依赖的package包/类
@org.junit.Test
public void testRSA_SHA_224() throws Exception {
// Read in plaintext document
InputStream sourceDocument =
this.getClass().getClassLoader().getResourceAsStream(
"ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
DocumentBuilder builder = XMLUtils.createDocumentBuilder(false);
Document document = builder.parse(sourceDocument);
List<String> localNames = new ArrayList<String>();
localNames.add("PaymentInfo");
sign(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA224, document, localNames, rsaKeyPair.getPrivate());
// XMLUtils.outputDOM(document, System.out);
verify(document, rsaKeyPair.getPublic(), localNames);
}
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:17,代码来源:PKSignatureAlgorithmTest.java
示例20: testSHA1
import org.apache.xml.security.utils.XMLUtils; //导入依赖的package包/类
@org.junit.Test
public void testSHA1() throws Exception {
Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
MessageDigestAlgorithm digestAlgorithm =
MessageDigestAlgorithm.getInstance(doc, MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA1);
assertEquals(MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA1, digestAlgorithm.getAlgorithmURI());
byte[] digest = digestAlgorithm.digest("test-string".getBytes());
assertNotNull(digest);
assertTrue(digest.length > 0);
// Now compare against a JDK MessageDigest Object
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] digest2 = md.digest("test-string".getBytes());
assertTrue(Arrays.equals(digest, digest2));
}
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:18,代码来源:DigestAlgorithmTest.java
注:本文中的org.apache.xml.security.utils.XMLUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论