Examples of SignatureAlgorithm


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

        super(reparseSignedInfoElem(element), baseURI);

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

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

        }

        try {
            //Create a SignatureAlgorithm object
             SignedInfo si = this.getSignedInfo();
            SignatureAlgorithm sa = si.getSignatureAlgorithm();              
            try {
                // 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));
                // get the canonicalized bytes from SignedInfo
                si.signInOctectStream(so);
               
                so.close();
            } catch (IOException ex) {
                // Impossible...but clear the signature cache anyway
                sa.clearSignatureCache();
            } catch (XMLSecurityException ex) {
                sa.clearSignatureCache();
                throw 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

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

        // 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.signInOctectStream(bos);
            bos.close();
            // retrieve the byte[] from the stored signature
            sigBytes = this.getSignatureValue();
          } catch (IOException ex) {
               // Impossible...but clear the verification cache anyway
              sa.clearVerificationCache();
          } catch (XMLSecurityException ex) {
              sa.clearVerificationCache();
              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

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

            // get the SignatureMethodElement
            Element signatureMethodElement =
               this._signedInfo.getSignatureMethodElement();

            //Create a SignatureAlgorithm object
            SignatureAlgorithm sa =
               new SignatureAlgorithm(signatureMethodElement,
                                      this.getBaseURI());

            // initialize SignatureAlgorithm for signing
            sa.initSign(signingKey);

            SignedInfo si = this.getSignedInfo();

            // 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

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

            return false;
         }

         //create a SignatureAlgorithms from the SignatureMethod inside
         //SignedInfo. This is used to validate the signature.
         SignatureAlgorithm sa =
            new SignatureAlgorithm(this.getSignedInfo()
               .getSignatureMethodElement(), this.getBaseURI());
         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);
         this._signedInfo.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

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

         this._constructionElement.appendChild(canonElem);
         XMLUtils.addReturnToElement(this._constructionElement);
      }
      {
         if (HMACOutputLength > 0) {
            this._signatureAlgorithm = new SignatureAlgorithm(this._doc,
                    SignatureMethodURI, HMACOutputLength);
         } else {
            this._signatureAlgorithm = new SignatureAlgorithm(this._doc,
                    SignatureMethodURI);
         }

         this._constructionElement
            .appendChild(this._signatureAlgorithm.getElement());
View Full Code Here

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

      super(doc);

      this._constructionElement.appendChild(CanonicalizationMethodElem);
      XMLUtils.addReturnToElement(this._constructionElement);

      this._signatureAlgorithm = new SignatureAlgorithm(SignatureMethodElem, null);

      this._constructionElement
         .appendChild(this._signatureAlgorithm.getElement());
      XMLUtils.addReturnToElement(this._constructionElement);
   }
View Full Code Here

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

      } catch (SAXException ex) {
         throw new XMLSecurityException("empty", ex);
      }
      }
      this._signatureAlgorithm =
         new SignatureAlgorithm(this.getSignatureMethodElement(),
                                this.getBaseURI());
   }
View Full Code Here

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

                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

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

    int keyIndex = 0;   
    byte[] currentKey = keyType;
      

    Document doc = dbf.newDocumentBuilder().newDocument();       
        SignatureAlgorithm sa = new SignatureAlgorithm(doc,
            SHAREDSECRET_HASH_ALGORITH,
                33);
       
        // Make the string saslpreped
        String sASLPrepedPassword = passphrase;
        if(performSASLprep){
          sASLPrepedPassword= Stringprep.saslprep(passphrase);
        }
       
        while(keyIndex < keylength){
          SecretKey sk = new SecretKeySpec(currentKey,
              sa.getJCEAlgorithmString());

          Mac m = Mac.getInstance("HmacSHA1");
          m.init(sk);
          m.update(sASLPrepedPassword.getBytes("ISO8859-1"));
          byte[] mac = m.doFinal();
          for(int i=0;i<mac.length;i++){
               if(keyIndex < keylength){
                 finalKey[keyIndex] = mac[i];
                 keyIndex++;
               }else{
                 break;
               }
          }
          mac[0] = (byte) (mac[0] ^ currentKey[0]);
          currentKey = mac;
         
          retval = new SecretKeySpec(finalKey,
              sa.getJCEAlgorithmString());
        }
    }catch(IllegalMonitorStateException e){
     
    } catch (ParserConfigurationException e) {
      log.error("Error generating secret key", e);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.