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


Java XMLSignatureException类代码示例

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


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

示例1: test222excl

import org.apache.xml.security.signature.XMLSignatureException; //导入依赖的package包/类
/**
 * Method test222excl
 *
 * @throws CanonicalizationException
 * @throws FileNotFoundException
 * @throws IOException
 * @throws InvalidCanonicalizerException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws TransformerException
 * @throws XMLSecurityException
 * @throws XMLSignatureException
 */
@org.junit.Test
public void test222excl()
    throws IOException, FileNotFoundException, SAXException,
    ParserConfigurationException, CanonicalizationException,
    InvalidCanonicalizerException, TransformerException,
    XMLSignatureException, XMLSecurityException {
    Document doc =
        this.db.parse(getAbsolutePath(
            "src/test/resources/org/apache/xml/security/c14n/inExcl/example2_2_2.xml"));
    Node root = doc.getElementsByTagNameNS("http://example.net", "elem2").item(0);
    Canonicalizer20010315Excl c = new Canonicalizer20010315ExclWithComments();
    byte[] reference = JavaUtils.getBytesFromFile(getAbsolutePath(
        "src/test/resources/org/apache/xml/security/c14n/inExcl/example2_2_c14nized_exclusive.xml") );
    byte[] result = c.engineCanonicalizeSubTree(root);
    boolean equals = java.security.MessageDigest.isEqual(reference, result);

    assertTrue(equals);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:32,代码来源:Canonicalizer20010315ExclusiveTest.java

示例2: write

import org.apache.xml.security.signature.XMLSignatureException; //导入依赖的package包/类
/** @inheritDoc */
public void write(byte[] arg0, int arg1, int arg2) {
    if (log.isDebugEnabled()) {
        log.debug("Canonicalized SignedInfo:");
        StringBuilder sb = new StringBuilder(arg2);
        for (int i = arg1; i < (arg1 + arg2); i++) {
            sb.append((char)arg0[i]);
        }
        log.debug(sb.toString());
    }
    try {
        sa.update(arg0, arg1, arg2);
    } catch (XMLSignatureException e) {
        throw new RuntimeException("" + e);
    }
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:17,代码来源:SignerOutputStream.java

示例3: testBug

import org.apache.xml.security.signature.XMLSignatureException; //导入依赖的package包/类
@org.junit.Test
public void testBug() throws Exception {
    Document document = getSignedDocument();
    NodeList list =
        document.getElementsByTagNameNS(Constants.SignatureSpecNS, Constants._TAG_SIGNATURE);
    Element element = (Element) list.item(0);
    XMLSignature signature = new XMLSignature(element, null);
    KeyInfo keyInfo = signature.getKeyInfo();
    X509Certificate certificate = keyInfo.getX509Certificate();
    assertNotNull(certificate);
    try {
        signature.checkSignatureValue(certificate);
    } catch (XMLSignatureException e) {
        fail(e.getMessage());
    }
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:17,代码来源:Bug45961Test.java

示例4: engineInitSign

import org.apache.xml.security.signature.XMLSignatureException; //导入依赖的package包/类
/** @inheritDoc */
protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
    throws XMLSignatureException {
    if (!(privateKey instanceof PrivateKey)) {
        String supplied = null;
        if (privateKey != null) {
            supplied = privateKey.getClass().getName();
        }
        String needed = PrivateKey.class.getName();
        Object exArgs[] = { supplied, needed };

        throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
    }

    try {
        if (secureRandom == null) {
            this.signatureAlgorithm.initSign((PrivateKey) privateKey);
        } else {
            this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
        }
    } catch (InvalidKeyException ex) {
        throw new XMLSignatureException(ex);
    }
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:25,代码来源:SignatureECDSA.java

示例5: test222

import org.apache.xml.security.signature.XMLSignatureException; //导入依赖的package包/类
/**
 * Method test222
 *
 * @throws CanonicalizationException
 * @throws FileNotFoundException
 * @throws IOException
 * @throws InvalidCanonicalizerException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws TransformerException
 * @throws XMLSecurityException
 * @throws XMLSignatureException
 */
@org.junit.Test
public void test222()
    throws IOException, FileNotFoundException, SAXException,
    ParserConfigurationException, CanonicalizationException,
    InvalidCanonicalizerException, TransformerException,
    XMLSignatureException, XMLSecurityException {
    Document doc =
        this.db.parse(getAbsolutePath(
            "src/test/resources/org/apache/xml/security/c14n/inExcl/example2_2_2.xml")
        );
    Node root = doc.getElementsByTagNameNS("http://example.net", "elem2").item(0);
    Canonicalizer20010315 c = new Canonicalizer20010315WithComments();
    byte[] reference = JavaUtils.getBytesFromFile(getAbsolutePath(
        "src/test/resources/org/apache/xml/security/c14n/inExcl/example2_2_2_c14nized.xml"));
    byte[] result = c.engineCanonicalizeSubTree(root);
    boolean equals = java.security.MessageDigest.isEqual(reference, result);

    assertTrue(equals);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:33,代码来源:Canonicalizer20010315ExclusiveTest.java

示例6: test_generate_hmac_sha1_40

import org.apache.xml.security.signature.XMLSignatureException; //导入依赖的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

示例7: test221excl

import org.apache.xml.security.signature.XMLSignatureException; //导入依赖的package包/类
/**
 * Method test221excl
 *
 * @throws CanonicalizationException
 * @throws FileNotFoundException
 * @throws IOException
 * @throws InvalidCanonicalizerException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws TransformerException
 * @throws XMLSecurityException
 * @throws XMLSignatureException
 */
@org.junit.Test
public void test221excl()
    throws IOException, FileNotFoundException, SAXException,
    ParserConfigurationException, CanonicalizationException,
    InvalidCanonicalizerException, TransformerException,
    XMLSignatureException, XMLSecurityException {
    Document doc =
        this.db.parse(getAbsolutePath(
            "src/test/resources/org/apache/xml/security/c14n/inExcl/example2_2_1.xml"));
    Node root = doc.getElementsByTagNameNS("http://example.net", "elem2").item(0);
    Canonicalizer20010315Excl c = new Canonicalizer20010315ExclWithComments();
    byte[] reference = JavaUtils.getBytesFromFile(getAbsolutePath(
        "src/test/resources/org/apache/xml/security/c14n/inExcl/example2_2_c14nized_exclusive.xml"));
    byte[] result = c.engineCanonicalizeSubTree(root);
    boolean equals = java.security.MessageDigest.isEqual(reference, result);

    assertTrue(equals);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:32,代码来源:Canonicalizer20010315ExclusiveTest.java

示例8: engineInitSign

import org.apache.xml.security.signature.XMLSignatureException; //导入依赖的package包/类
/**
 * @inheritDoc
 */
protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
    throws XMLSignatureException {
    if (!(privateKey instanceof PrivateKey)) {
        String supplied = null;
        if (privateKey != null) {
            supplied = privateKey.getClass().getName();
        }
        String needed = PrivateKey.class.getName();
        Object exArgs[] = { supplied, needed };

        throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
    }

    try {
        if (secureRandom == null) {
            this.signatureAlgorithm.initSign((PrivateKey) privateKey);
        } else {
            this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
        }
    } catch (InvalidKeyException ex) {
        throw new XMLSignatureException(ex);
    }
    size = ((DSAKey)privateKey).getParams().getQ().bitLength();
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:28,代码来源:SignatureDSA.java

示例9: engineVerify

import org.apache.xml.security.signature.XMLSignatureException; //导入依赖的package包/类
/**
 * Proxy method for {@link java.security.Signature#verify(byte[])}
 * which is executed on the internal {@link java.security.Signature} object.
 *
 * @param signature
 * @return true if the signature is correct
 * @throws XMLSignatureException
 */
protected boolean engineVerify(byte[] signature) throws XMLSignatureException {
    try {
        if (this.HMACOutputLengthSet && this.HMACOutputLength < getDigestLength()) {
            if (log.isDebugEnabled()) {
                log.debug("HMACOutputLength must not be less than " + getDigestLength());
            }
            Object[] exArgs = { String.valueOf(getDigestLength()) };
            throw new XMLSignatureException("algorithms.HMACOutputLengthMin", exArgs);
        } else {
            byte[] completeResult = this.macAlgorithm.doFinal();
            return MessageDigestAlgorithm.isEqual(completeResult, signature);
        }
    } catch (IllegalStateException ex) {
        throw new XMLSignatureException(ex);
    }
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:25,代码来源:IntegrityHmac.java

示例10: engineSign

import org.apache.xml.security.signature.XMLSignatureException; //导入依赖的package包/类
/**
 * Proxy method for {@link java.security.Signature#sign()}
 * which is executed on the internal {@link java.security.Signature} object.
 *
 * @return the result of the {@link java.security.Signature#sign()} method
 * @throws XMLSignatureException
 */
protected byte[] engineSign() throws XMLSignatureException {
    try {
        if (this.HMACOutputLengthSet && this.HMACOutputLength < getDigestLength()) {
            if (log.isDebugEnabled()) {
                log.debug("HMACOutputLength must not be less than " + getDigestLength());
            }
            Object[] exArgs = { String.valueOf(getDigestLength()) };
            throw new XMLSignatureException("algorithms.HMACOutputLengthMin", exArgs);
        } else {
            return this.macAlgorithm.doFinal();
        }
    } catch (IllegalStateException ex) {
        throw new XMLSignatureException(ex);
    }
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:23,代码来源:IntegrityHmac.java

示例11: test221

import org.apache.xml.security.signature.XMLSignatureException; //导入依赖的package包/类
/**
 * Method test221
 *
 * @throws CanonicalizationException
 * @throws FileNotFoundException
 * @throws IOException
 * @throws InvalidCanonicalizerException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws TransformerException
 * @throws XMLSecurityException
 * @throws XMLSignatureException
 */
@org.junit.Test
public void test221()
    throws IOException, FileNotFoundException, SAXException,
    ParserConfigurationException, CanonicalizationException,
    InvalidCanonicalizerException, TransformerException,
    XMLSignatureException, XMLSecurityException {

    Document doc =
        this.db.parse(
            getAbsolutePath("src/test/resources/org/apache/xml/security/c14n/inExcl/example2_2_1.xml")
        );
    Node root = doc.getElementsByTagNameNS("http://example.net", "elem2").item(0);
    Canonicalizer20010315 c = new Canonicalizer20010315WithComments();
    byte[] reference = JavaUtils.getBytesFromFile(getAbsolutePath(
        "src/test/resources/org/apache/xml/security/c14n/inExcl/example2_2_1_c14nized.xml"));
    byte[] result = c.engineCanonicalizeSubTree(root);
    boolean equals = java.security.MessageDigest.isEqual(reference, result);

    assertTrue(equals);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:34,代码来源:Canonicalizer20010315ExclusiveTest.java

示例12: register

import org.apache.xml.security.signature.XMLSignatureException; //导入依赖的package包/类
/**
 * Registers implementing class of the SignatureAlgorithm with algorithmURI
 *
 * @param algorithmURI algorithmURI URI representation of <code>SignatureAlgorithm</code>.
 * @param implementingClass <code>implementingClass</code> the implementing class of
 * {@link SignatureAlgorithmSpi}
 * @throws AlgorithmAlreadyRegisteredException if specified algorithmURI is already registered
 * @throws XMLSignatureException
 * @throws SecurityException if a security manager is installed and the
 *    caller does not have permission to register the signature algorithm
 */
public static void register(String algorithmURI, Class<? extends SignatureAlgorithmSpi> implementingClass)
   throws AlgorithmAlreadyRegisteredException, ClassNotFoundException,
       XMLSignatureException {
    JavaUtils.checkRegisterPermission();
    if (log.isDebugEnabled()) {
        log.debug("Try to register " + algorithmURI + " " + implementingClass);
    }

    // are we already registered?
    Class<? extends SignatureAlgorithmSpi> registeredClass = algorithmHash.get(algorithmURI);
    if (registeredClass != null) {
        Object exArgs[] = { algorithmURI, registeredClass };
        throw new AlgorithmAlreadyRegisteredException(
            "algorithm.alreadyRegistered", exArgs
        );
    }
    algorithmHash.put(algorithmURI, implementingClass);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:30,代码来源:SignatureAlgorithm.java

示例13: getTransforms

import org.apache.xml.security.signature.XMLSignatureException; //导入依赖的package包/类
/**
 * Method getTransforms
 *
 * @throws XMLSecurityException
 * @return the transformations
 */
public Transforms getTransforms() throws XMLSecurityException {
    try {
        Element transformsElem =
            XMLUtils.selectDsNode(
                getFirstChild(), Constants._TAG_TRANSFORMS, 0);

        if (transformsElem != null) {
            return new Transforms(transformsElem, this.baseURI);
        }

        return null;
    } catch (XMLSignatureException ex) {
        throw new XMLSecurityException(ex);
    }
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:22,代码来源:RetrievalMethod.java

示例14: testWrappingAttack

import org.apache.xml.security.signature.XMLSignatureException; //导入依赖的package包/类
@org.junit.Test
public void testWrappingAttack() throws Exception {
    boolean success =
        readAndVerifySignature(
            "src/test/resources/at/iaik/ixsil/coreFeatures/signatures",
            "manifestSignatureWrapping.xml"
        );

    assertTrue(success);
    try {
        readAndVerifySignatureAndSetManifest(
            "src/test/resources/at/iaik/ixsil/coreFeatures/signatures",
            "manifestSignatureWrapping.xml"
        );
        fail("Failure expected when secure validation is enabled");
    } catch (XMLSignatureException ex) {
        assertTrue(ex.getMessage().contains("no XMLSignatureInput"));
    }
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:20,代码来源:WrappingAttackTest.java

示例15: validate

import org.apache.xml.security.signature.XMLSignatureException; //导入依赖的package包/类
/** {@inheritDoc} */
public void validate(Signature signature) throws ValidationException {
    log.debug("Attempting to validate signature using key from supplied credential");

    XMLSignature xmlSig = buildSignature(signature);

    Key validationKey = SecurityHelper.extractVerificationKey(validationCredential);
    if (validationKey == null) {
        log.debug("Supplied credential contained no key suitable for signature validation");
        throw new ValidationException("No key available to validate signature");
    }
    
    log.debug("Validating signature with signature algorithm URI: {}", signature.getSignatureAlgorithm());
    log.debug("Validation credential key algorithm '{}', key instance class '{}'", 
            validationKey.getAlgorithm(), validationKey.getClass().getName());

    try {
        if (xmlSig.checkSignatureValue(validationKey)) {
            log.debug("Signature validated with key from supplied credential");
            return;
        }
    } catch (XMLSignatureException e) {
        throw new ValidationException("Unable to evaluate key against signature", e);
    }

    log.debug("Signature did not validate against the credential's key");

    throw new ValidationException("Signature did not validate against the credential's key");
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:SignatureValidator.java


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