Package org.apache.xml.security.algorithms

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


      try {
         if (this._state == MODE_SIGN) {
            //Create a SignatureAlgorithm object
          SignedInfo si = this.getSignedInfo();
            SignatureAlgorithm sa = si.getSignatureAlgorithm();              
            // initialize SignatureAlgorithm for signing
            sa.initSign(signingKey);           

            // generate digest values for all References in this SignedInfo
            si.generateDigestValues();
            OutputStream so=new UnsyncBufferedOutputStream(new SignerOutputStream(sa));
            try {
                so.close();
            } catch (IOException e) {
                //Imposible
            }
            // get the canonicalized bytes from SignedInfo
            si.signInOctectStream(so);

            byte jcebytes[] = sa.sign();

            // set them on the SignateValue element
            this.setSignatureValueElement(jcebytes);
         }
      } catch (CanonicalizationException ex) {
View Full Code Here


            return false;
         }

         //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);
         }
         sa.initVerify(pk);

         // Get the canonicalized (normalized) SignedInfo
         SignerOutputStream so=new SignerOutputStream(sa);
         OutputStream bos=new UnsyncBufferedOutputStream(so);
         si.signInOctectStream(bos);
         try {
      bos.close();
    } catch (IOException e) {
      //Imposible
    }
        
         //retrieve the byte[] from the stored signature
         byte sigBytes[] = this.getSignatureValue();


         //Have SignatureAlgorithm sign the input bytes and compare them to the
         //bytes that were stored in the signature.
         boolean verify = sa.verify(sigBytes);

         return verify;
      } catch (XMLSecurityException ex) {
         throw new XMLSignatureException("empty", ex);
      }
View Full Code Here

      org.apache.xml.security.Init.init();
  }

  public void testSameKeySeveralAlgorithmSigning() throws Exception {
    Document doc=DocumentBuilderFactory.newInstance().newDocumentBuilder().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

        Element canonElem = 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);
View Full Code Here

import org.w3c.dom.Document;

public class SignatureAlgorithmTest extends TestCase {
  public void testSameKeySeveralAlgorithSigning() throws Exception {
    Document doc=DocumentBuilderFactory.newInstance().newDocumentBuilder().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);
    otherSignatureAlgorithm.initSign(pk);
    otherSignatureAlgorithm.update((byte)2);
    otherSignatureAlgorithm.sign();
  }
View Full Code Here

      org.apache.xml.security.Init.init();
  }

  public void testSameKeySeveralAlgorithSigning() throws Exception {
    Document doc=DocumentBuilderFactory.newInstance().newDocumentBuilder().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);
    otherSignatureAlgorithm.initSign(pk);
    otherSignatureAlgorithm.update((byte)2);
    otherSignatureAlgorithm.sign();
  }
View Full Code Here

        Element canonElem = 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);
View Full Code Here

        Element canonElem = 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);
View Full Code Here

      org.apache.xml.security.Init.init();
  }

  public void testSameKeySeveralAlgorithSigning() throws Exception {
    Document doc=DocumentBuilderFactory.newInstance().newDocumentBuilder().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);
    otherSignatureAlgorithm.initSign(pk);
    otherSignatureAlgorithm.update((byte)2);
    otherSignatureAlgorithm.sign();
  }
View Full Code Here

        Element canonElem = 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);
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.