Package org.apache.xml.security.algorithms.encryption

Examples of org.apache.xml.security.algorithms.encryption.EncryptionMethod


   public EncryptedData(
           Document doc, String encryptionMethod, EncryptionMethodParams encryptionMethodParams, KeyInfo keyInfo, EncryptionProperties encryptionProperties, String Id)
              throws XMLSecurityException {

      this(doc,
           new EncryptionMethod(doc, encryptionMethod, encryptionMethodParams),
           keyInfo, (CipherData) null, encryptionProperties, Id, (String) null);
   }
View Full Code Here


           Document doc, String encryptionMethod,
           EncryptionMethodParams encryptionMethodParams, KeyInfo keyInfo, CipherData cipherData, EncryptionProperties encryptionProperties, String Id, String Type)
              throws XMLSecurityException {

      this(doc,
           new EncryptionMethod(doc, encryptionMethod, encryptionMethodParams),
           keyInfo, cipherData, encryptionProperties, Id, Type);
   }
View Full Code Here

            XMLUtils.getDirectChild(this._constructionElement,
                                    EncryptionConstants._TAG_ENCRYPTIONMETHOD,
                                    EncryptionConstants.EncryptionSpecNS);

         if (e != null) {
            this._cachedEncryptionMethod = new EncryptionMethod(e,
                    this._baseURI);
         }
      }

      return this._cachedEncryptionMethod;
View Full Code Here

    * @throws XMLSecurityException
    */
   public void encryptElementAndReplace(Element plaintextElement, Key secretKey)
           throws XMLSecurityException {

      EncryptionMethod em = this.getEncryptionMethod();
      Canonicalizer c14n =
         Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS);
      byte plaintext[] = c14n.canonicalizeSubtree(plaintextElement);
      byte ciphertext[] = em.encrypt(plaintext, secretKey);

      this.getCipherData().setCipherValue(new CipherValue(this._doc,
              ciphertext));
      this.setType(EncryptionConstants.TYPE_ELEMENT);
      EncryptedData.replace(plaintextElement, this._constructionElement);
View Full Code Here

    */
   private void encryptContentAndReplace_old(
           Node parentOfPlaintext, Key contentEncryptionKey)
              throws XMLSecurityException {

      EncryptionMethod em = this.getEncryptionMethod();
      byte plaintext[] = null;

      try {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();

         for (int i = 0; i < parentOfPlaintext.getChildNodes().getLength();
                 i++) {
            Node plaintextItem = parentOfPlaintext.getChildNodes().item(i);

            // we cannot c14nize Comments, and PIs because the c14nizer appends CRs to the String
            if (plaintextItem.getNodeType() == Node.COMMENT_NODE) {
               baos.write(("<!--" + ((Comment) plaintextItem).getData()
                           + "-->").getBytes());
            } else if (plaintextItem.getNodeType()
                       == Node.PROCESSING_INSTRUCTION_NODE) {
               baos.write(("<?"
                           + ((ProcessingInstruction) plaintextItem).getTarget()
                           + " "
                           + ((ProcessingInstruction) plaintextItem).getData()
                           + "?>").getBytes());
            } else if (plaintextItem.getNodeType() == Node.TEXT_NODE) {
               baos.write((((Text) plaintextItem).getData()).getBytes());
            } else {

               // we have to create a new Canonicalizer for each Node because it stores state ;-(
               Canonicalizer c14n =
                  Canonicalizer
                     .getInstance(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS);

               baos.write(c14n.canonicalizeSubtree(plaintextItem));
            }
         }

         plaintext = baos.toByteArray();
      } catch (Exception ex) {
         throw new XMLSecurityException("empty", ex);
      }

      byte ciphertext[] = em.encrypt(plaintext, contentEncryptionKey);

      this.getCipherData().setCipherValue(new CipherValue(this._doc,
              ciphertext));
      this.setType(EncryptionConstants.TYPE_CONTENT);

View Full Code Here

   public void encryptContentAndReplace(
           Node firstPlaintextNode, int length, Key contentEncryptionKey)
              throws XMLSecurityException {

      try {
         EncryptionMethod em = this.getEncryptionMethod();
         byte plaintext[] = null;
         Node parent = firstPlaintextNode.getParentNode();
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         Node currentNode = firstPlaintextNode;
         int i = 0;

         while (i < length) {
            if (currentNode == null) {
               throw new IndexOutOfBoundsException(
                  "The index " + length + " is out of bounds: maximum is "
                  + (i - 1));
            }

            // we cannot c14nize Comments, and PIs because the c14nizer appends CRs to the String
            if (currentNode.getNodeType() == Node.COMMENT_NODE) {
               baos.write(("<!--" + ((Comment) currentNode).getData()
                           + "-->").getBytes());
            } else if (currentNode.getNodeType()
                       == Node.PROCESSING_INSTRUCTION_NODE) {
               baos.write(("<?"
                           + ((ProcessingInstruction) currentNode).getTarget()
                           + " "
                           + ((ProcessingInstruction) currentNode).getData()
                           + "?>").getBytes());
            } else if (currentNode.getNodeType() == Node.TEXT_NODE) {
               baos.write((((Text) currentNode).getData()).getBytes());
            } else {

               // we have to create a new Canonicalizer for each Node because it stores state ;-(
               Canonicalizer c14n =
                  Canonicalizer
                     .getInstance(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS);

               baos.write(c14n.canonicalizeSubtree(currentNode));
            }

            currentNode = currentNode.getNextSibling();
            i = i + 1;
         }

         Node insertBeforeNode = currentNode;

         plaintext = baos.toByteArray();

         byte ciphertext[] = em.encrypt(plaintext, contentEncryptionKey);

         this.getCipherData().setCipherValue(new CipherValue(this._doc,
                 ciphertext));
         this.setType(EncryptionConstants.TYPE_CONTENT);
View Full Code Here

    * @throws XMLSecurityException
    */
   public void decryptAndReplace(Key contentDecryptionKey)
           throws XMLSecurityException {

      EncryptionMethod em = this.getEncryptionMethod();
      byte ciphertext[] = this.getCipherData().getCipherValue().getCipherText();
      byte plaintext[] = em.decrypt(ciphertext, contentDecryptionKey);

      try {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         String container = "container";

View Full Code Here

      super(doc);

      XMLUtils.addReturnToElement(this._constructionElement);

      EncryptionMethod encryptionMethod = new EncryptionMethod(doc,
                                             encryptionMethodURI,
                                             encryptionMethodParams);

      if (!encryptionMethod.getUsableInEncryptedKey()) {
         Object exArgs[] = { encryptionMethod.getAlgorithmURI() };

         throw new XMLSecurityException(
            "encryption.algorithmCannotBeUsedForEncryptedKey", exArgs);
      }

      this._constructionElement.appendChild(encryptionMethod.getElement());
      XMLUtils.addReturnToElement(this._constructionElement);

      if (keyInfo != null) {
         this._constructionElement.appendChild(keyInfo.getElement());
         XMLUtils.addReturnToElement(this._constructionElement);
      }
      {
         byte wrappedKey[] = encryptionMethod.wrap(contentKey, wrapKey);
         CipherData cipherData = new CipherData(doc, wrappedKey);
         this._constructionElement.appendChild(cipherData.getElement());
         XMLUtils.addReturnToElement(this._constructionElement);
      }
View Full Code Here

         XMLUtils.getDirectChild(this._constructionElement,
                                 EncryptionConstants._TAG_ENCRYPTIONMETHOD,
                                 EncryptionConstants.EncryptionSpecNS);

      if (e != null) {
         return new EncryptionMethod(e, this._baseURI);
      } else {
         return null;
      }
   }
View Full Code Here

      dbf.setNamespaceAware(true);

      javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
      Document doc = db.newDocument();
      EncryptionMethod em =
         new EncryptionMethod(doc, EncryptionConstants.ALGO_ID_KEYWRAP_AES128);
      Key wrapKey = em.createSecretKeyFromBytes(
         org.apache.xml.security.utils.HexDump.hexStringToByteArray(
            "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f"));
      Key contentKey = em.createSecretKeyFromBytes(
         org.apache.xml.security.utils.HexDump.hexStringToByteArray(
            "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f"));
      byte ciphertext[] = em.wrap(contentKey, wrapKey);
      KeyInfo ki = new KeyInfo(doc);

      ki.add(new org.apache.xml.security.keys.content.KeyName(doc,
              "Christian Geuer-Pollmann"));

      EncryptedKey ed = new EncryptedKey(doc, em, ki,
                                         new CipherData(doc, ciphertext), null,
                                         null, "Christian Geuer-Pollmann", "",
                                         EncryptionConstants.TYPE_CONTENT,
                                         "Ed Simon");

      doc.appendChild(ed.getElement());
      org.apache.xml.security.utils.XMLUtils.outputDOMc14nWithComments(doc,
              System.out);

      EncryptionMethod em2 = ed.getEncryptionMethod();
      byte[] ciphertext2 = ed.getCipherData().getCipherValue().getCipherText();
      Key decrypt = em2.createSecretKeyFromBytes(
         org.apache.xml.security.utils.HexDump.hexStringToByteArray(
            "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f"));
      Key unwrapped =
         em2.unwrap(ciphertext2, wrapKey,
                    EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES128);

      System.out.println();
      System.out.println();
      System.out.println();
View Full Code Here

TOP

Related Classes of org.apache.xml.security.algorithms.encryption.EncryptionMethod

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.