Package org.apache.xml.security.algorithms

Examples of org.apache.xml.security.algorithms.SignatureAlgorithm


            XMLUtils.createElementInSignatureSpace(doc, Constants._TAG_CANONICALIZATIONMETHOD);
        canonElem.setAttributeNS(
            null, Constants._ATT_ALGORITHM, Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS
        );

        SignatureAlgorithm signatureAlgorithm =
            new SignatureAlgorithm(doc, XMLSignature.ALGO_ID_SIGNATURE_DSA);
        XMLSignature sig =
            new XMLSignature(doc, null, signatureAlgorithm.getElement(), canonElem);

        root.appendChild(sig.getElement());
        doc.appendChild(doc.createComment(" Comment after "));
        Transforms transforms = new Transforms(doc);
        transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
View Full Code Here


            XMLUtils.createElementInSignatureSpace(doc, Constants._TAG_CANONICALIZATIONMETHOD);
        canonElem.setAttributeNS(
            null, Constants._ATT_ALGORITHM, Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS
        );

        SignatureAlgorithm signatureAlgorithm =
            new SignatureAlgorithm(doc, XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA1);
        XMLSignature sig =
            new XMLSignature(doc, null, signatureAlgorithm.getElement(), canonElem);

        root.appendChild(sig.getElement());
        doc.appendChild(doc.createComment(" Comment after "));
        Transforms transforms = new Transforms(doc);
        transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
View Full Code Here

                canonElem.appendChild(inclusiveNamespaces.getElement());
            }

            try {
                SignatureAlgorithm signatureAlgorithm = new SignatureAlgorithm(
                        doc, sigAlgo);
                sig = new XMLSignature(doc, null, signatureAlgorithm
                        .getElement(), canonElem);
            } catch (XMLSecurityException e) {
                log.error("", e);
                throw new WSSecurityException(
                        WSSecurityException.FAILED_SIGNATURE, "noXMLSig");
View Full Code Here

                canonElem.appendChild(inclusiveNamespaces.getElement());
            }

            try {
                SignatureAlgorithm signatureAlgorithm = new SignatureAlgorithm(
                        doc, sigAlgo);
                sig = new XMLSignature(doc, null, signatureAlgorithm
                        .getElement(), canonElem);
            } catch (XMLSecurityException e) {
                log.error("", e);
                throw new WSSecurityException(
                        WSSecurityException.FAILED_SIGNATURE, "noXMLSig");
View Full Code Here

        canonElem.appendChild(inclusiveNamespaces.getElement());
      }

      try {
        SignatureAlgorithm signatureAlgorithm = new SignatureAlgorithm(
            doc, sigAlgo);
        sig = new XMLSignature(doc, null, signatureAlgorithm
            .getElement(), canonElem);
      } catch (XMLSecurityException e) {
        log.error("", e);
        throw new WSSecurityException(
            WSSecurityException.FAILED_SIGNATURE, "noXMLSig");
View Full Code Here

      DocumentBuilder db = dbf.newDocumentBuilder();
      Document doc = db.newDocument();

      // SignatureAlgorithm sa = SignatureAlgorithm.getInstance(doc, XMLSignature.ALGO_ID_SIGNATURE_DSA, 120);
      SignatureAlgorithm sa = new SignatureAlgorithm(doc,
                                 "http://www.w3.org/2000/09/xmldsig#dsa-sha1");

      sa.initSign(privateKey);
      sa.update("sdjhfkjashkjf".getBytes());

      byte signatureValue[] = sa.sign();

      System.out.println(Base64.encode(signatureValue));
      doc.appendChild(sa.getElement());
      XMLUtils.outputDOM(doc, System.out);
      System.out.println("");
      System.out.println("");

      SignatureAlgorithm verifyer =
         new SignatureAlgorithm(doc.getDocumentElement(), "file:");

      verifyer.initVerify(publicKey);
      verifyer.update("sdjhfkjashkjf".getBytes());

      boolean result = verifyer.verify(signatureValue);

      if (result) {
         System.out.println("It verified");
      } else {
         System.out.println("It failed");
View Full Code Here

      DocumentBuilder db = dbf.newDocumentBuilder();
      Document doc = db.newDocument();

      // SignatureAlgorithm sa = SignatureAlgorithm.getInstance(doc, XMLSignature.ALGO_ID_SIGNATURE_DSA, 120);
      SignatureAlgorithm sa = new SignatureAlgorithm(doc,
                                 "http://www.w3.org/2000/09/xmldsig#hmac-sha1",
                                 33);

      // SecretKeyFactory skf = SecretKeyFactory.getInstance(sa.getJCEAlgorithmString(), sa.getJCEProviderName());
      byte keybytes[] = "01234567890123456789".getBytes();
      SecretKey sk = new SecretKeySpec(keybytes, sa.getJCEAlgorithmString());

      sa.initSign(sk);
      sa.update("sdjhfkjashkjf".getBytes());

      byte signatureValue[] = sa.sign();

      System.out.println(Base64.encode(signatureValue));
      doc.appendChild(sa.getElement());
      XMLUtils.outputDOM(doc, System.out);
      System.out.println("");
      System.out.println("");

      javax.crypto.Mac a;
      SignatureAlgorithm verifyer =
         new SignatureAlgorithm(doc.getDocumentElement(), "file:");
      SecretKey pk = new SecretKeySpec("01234567890123456789".getBytes(),
                                       verifyer.getJCEAlgorithmString());

      verifyer.initVerify(pk);
      verifyer.update("sdjhfkjashkjf".getBytes());

      boolean result = verifyer.verify(signatureValue);

      if (result) {
         System.out.println("It verified");
      } else {
         System.out.println("It failed");
View Full Code Here

    }

    @org.junit.Test
    public void testSameKeySeveralAlgorithmSigning() throws Exception {
        Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
        SignatureAlgorithm signatureAlgorithm =
            new SignatureAlgorithm(doc, XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1);
        PrivateKey pk = KeyPairGenerator.getInstance("RSA").genKeyPair().getPrivate();
        signatureAlgorithm.initSign(pk);
        signatureAlgorithm.update((byte)2);
        signatureAlgorithm.sign();
        SignatureAlgorithm otherSignatureAlgorithm =
            new SignatureAlgorithm(doc, XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256);

        try {
            otherSignatureAlgorithm.initSign(pk);
        } catch (XMLSecurityException ex) {
            log.warn(
                "Test testSameKeySeveralAlgorithmSigning skipped as necessary algorithms "
                + "not available"
            );
            return;
        }

        otherSignatureAlgorithm.update((byte)2);
        otherSignatureAlgorithm.sign();
    }
View Full Code Here

            XMLUtils.createElementInSignatureSpace(doc, Constants._TAG_CANONICALIZATIONMETHOD);
        canonElem.setAttributeNS(
            null, Constants._ATT_ALGORITHM, Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS
        );

        SignatureAlgorithm signatureAlgorithm =
            new SignatureAlgorithm(doc, XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA1);
        XMLSignature sig =
            new XMLSignature(doc, null, signatureAlgorithm.getElement(), canonElem);

        root.appendChild(sig.getElement());
        doc.appendChild(doc.createComment(" Comment after "));
        Transforms transforms = new Transforms(doc);
        transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
View Full Code Here

            XMLUtils.createElementInSignatureSpace(doc, Constants._TAG_CANONICALIZATIONMETHOD);
        canonElem.setAttributeNS(
            null, Constants._ATT_ALGORITHM, Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS
        );

        SignatureAlgorithm signatureAlgorithm =
            new SignatureAlgorithm(doc, XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1);
        XMLSignature sig =
            new XMLSignature(doc, null, signatureAlgorithm.getElement(), canonElem);

        root.appendChild(sig.getElement());
        doc.appendChild(doc.createComment(" Comment after "));
        Transforms transforms = new Transforms(doc);
        transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
View Full Code Here

TOP

Related Classes of org.apache.xml.security.algorithms.SignatureAlgorithm

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.