Package org.apache.xml.security.algorithms

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


      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


        dbf.setNamespaceAware(true);

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

        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 verifier =
            new SignatureAlgorithm(doc.getDocumentElement(), "file:");

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

        boolean result = verifier.verify(signatureValue);

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

        dbf.setNamespaceAware(true);

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

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

        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 verifier =
            new SignatureAlgorithm(doc.getDocumentElement(), "file:");
        SecretKey pk =
            new SecretKeySpec("01234567890123456789".getBytes(), verifier.getJCEAlgorithmString());

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

        boolean result = verifier.verify(signatureValue);

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

        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();
View Full Code Here

        this.c14nMethod = canonicalizationMethodElem;
        appendSelf(c14nMethod);
        addReturnToSelf();

        this.signatureAlgorithm =
            new SignatureAlgorithm(signatureMethodElem, null);

        signatureMethod = this.signatureAlgorithm.getElement();
        appendSelf(signatureMethod);

        addReturnToSelf();
View Full Code Here

        super(reparseSignedInfoElem(element, secureValidation), baseURI, secureValidation);

        c14nMethod = XMLUtils.getNextElement(element.getFirstChild());
        signatureMethod = XMLUtils.getNextElement(c14nMethod.getNextSibling());
        this.signatureAlgorithm =
            new SignatureAlgorithm(signatureMethod, this.getBaseURI(), secureValidation);
    }
View Full Code Here

        }

        try {
            //Create a SignatureAlgorithm object
            SignedInfo si = this.getSignedInfo();
            SignatureAlgorithm sa = si.getSignatureAlgorithm();
            OutputStream so = null;
            try {
                // initialize SignatureAlgorithm for signing
                sa.initSign(signingKey);           

                // generate digest values for all References in this SignedInfo
                si.generateDigestValues();
                so = new UnsyncBufferedOutputStream(new SignerOutputStream(sa));
                // get the canonicalized bytes from SignedInfo
                si.signInOctetStream(so);
            } catch (XMLSecurityException ex) {
                throw ex;
            } finally {
                if (so != null) {
                    try {
                        so.close();
                    } catch (IOException ex) {
                        if (log.isDebugEnabled()) {
                            log.debug(ex.getMessage(), ex);
                        }
                    }
                }
            }

            // set them on the SignatureValue element
            this.setSignatureValueElement(sa.sign());
        } catch (XMLSignatureException ex) {
            throw ex;
        } catch (CanonicalizationException ex) {
            throw new XMLSignatureException("empty", ex);
        } catch (InvalidCanonicalizerException ex) {
View Full Code Here

        // References inside a Manifest.
        try {
            SignedInfo si = this.getSignedInfo();
            //create a SignatureAlgorithms from the SignatureMethod inside
            //SignedInfo. This is used to validate the signature.
            SignatureAlgorithm sa = si.getSignatureAlgorithm();              
            if (log.isDebugEnabled()) {
                log.debug("signatureMethodURI = " + sa.getAlgorithmURI());
                log.debug("jceSigAlgorithm    = " + sa.getJCEAlgorithmString());
                log.debug("jceSigProvider     = " + sa.getJCEProviderName());
                log.debug("PublicKey = " + pk);
            }
            byte sigBytes[] = null;
            try {
                sa.initVerify(pk);

                // Get the canonicalized (normalized) SignedInfo
                SignerOutputStream so = new SignerOutputStream(sa);
                OutputStream bos = new UnsyncBufferedOutputStream(so);

                si.signInOctetStream(bos);
                bos.close();
                // retrieve the byte[] from the stored signature
                sigBytes = this.getSignatureValue();
            } catch (IOException ex) {
                if (log.isDebugEnabled()) {
                    log.debug(ex.getMessage(), ex);
                }
                // Impossible...
            } catch (XMLSecurityException ex) {
                throw ex;
            }

            // have SignatureAlgorithm sign the input bytes and compare them to
            // the bytes that were stored in the signature.
            if (!sa.verify(sigBytes)) {
                log.warn("Signature verification failed.");
                return false;
            }

            return si.verify(this.followManifestsDuringValidation);
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", null, e
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", null, e
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.