Package org.apache.xml.security.encryption

Examples of org.apache.xml.security.encryption.EncryptedData


            //decrypt
            cipher = XMLCipher.getInstance(XMLCipher.AES_256);
            cipher.init(XMLCipher.DECRYPT_MODE, key);
            ee = (Element) ed.getElementsByTagName("xenc:EncryptedData").item(0);
      EncryptedData encryptedData = cipher.loadEncryptedData(ed, ee);
      Assert.assertEquals(encryptedData.getEncryptionMethod().getAlgorithm(),
                XMLCipher.AES_256);
            dd = cipher.doFinal(ed, ee);

            target = toString(dd);
      Assert.assertEquals(source, target);
View Full Code Here


      d.appendChild(docElement);

      // Create the XMLCipher object
      cipher = XMLCipher.getInstance();

      EncryptedData ed =
        cipher.createEncryptedData(CipherData.REFERENCE_TYPE,
                     "#CipherTextId");
      EncryptionMethod em =
        cipher.createEncryptionMethod(XMLCipher.AES_128);

      ed.setEncryptionMethod(em);

      org.apache.xml.security.encryption.Transforms xencTransforms =
        cipher.createTransforms(d);
      ed.getCipherData().getCipherReference().setTransforms(xencTransforms);
      org.apache.xml.security.transforms.Transforms dsTransforms =
        xencTransforms.getDSTransforms();

      // An XPath transform
      XPathContainer xpc = new XPathContainer(d);
View Full Code Here

        canon.notReset();
        canon.canonicalizeSubtree(e);
        baos.close();
        String before = baos.toString("UTF-8");

        EncryptedData encryptedData = cipher.encryptData
            (d, EncryptionConstants.TYPE_ELEMENT,
             new ByteArrayInputStream(baos.toByteArray()));

        //decrypt
        cipher = XMLCipher.getInstance(XMLCipher.AES_128);
        cipher.init(XMLCipher.DECRYPT_MODE, key);
        Assert.assertEquals
            (encryptedData.getEncryptionMethod().getAlgorithm(),
             XMLCipher.AES_128);
        byte[] bytes = cipher.decryptToByteArray(cipher.martial(encryptedData));
        String after = new String(bytes, "UTF-8");
        Assert.assertEquals(before, after);
    }
View Full Code Here

    // Need to pre-load the Encrypted Data so we can get the key info

    ee = (Element) doc.getElementsByTagName("EncryptedData").item(0);
    cipher.init(XMLCipher.DECRYPT_MODE, null);
    EncryptedData encryptedData = cipher.loadEncryptedData(doc, ee);
  
    Key key = findKey(encryptedData);
    cipher.init(XMLCipher.DECRYPT_MODE, key);
    Document dd = cipher.doFinal(doc, ee);
View Full Code Here

    // Need to pre-load the Encrypted Data so we can get the key info

    ee = (Element) doc.getElementsByTagName("EncryptedData").item(0);
    cipher.init(XMLCipher.DECRYPT_MODE, null);
    EncryptedData encryptedData = cipher.loadEncryptedData(doc, ee);

    Key key = findKey(encryptedData);
   
    cipher.init(XMLCipher.DECRYPT_MODE, key);
              
View Full Code Here

      EncryptedKey encryptedKey = cipher.encryptKey(d, key);

            // encrypt
            cipher = XMLCipher.getInstance(XMLCipher.AES_128);
            cipher.init(XMLCipher.ENCRYPT_MODE, key);
      EncryptedData builder = cipher.getEncryptedData();

      KeyInfo builderKeyInfo = builder.getKeyInfo();
      if (builderKeyInfo == null) {
        builderKeyInfo = new KeyInfo(d);
        builder.setKeyInfo(builderKeyInfo);
      }

      builderKeyInfo.add(encryptedKey);

            ed = cipher.doFinal(d, e);
View Full Code Here

      EncryptedKey encryptedKey = cipher.encryptKey(d, key);

            // encrypt
            cipher = XMLCipher.getInstance(XMLCipher.AES_256);
            cipher.init(XMLCipher.ENCRYPT_MODE, key);
      EncryptedData builder = cipher.getEncryptedData();

      KeyInfo builderKeyInfo = builder.getKeyInfo();
      if (builderKeyInfo == null) {
        builderKeyInfo = new KeyInfo(d);
        builder.setKeyInfo(builderKeyInfo);
      }

      builderKeyInfo.add(encryptedKey);

            ed = cipher.doFinal(d, e);
View Full Code Here

      EncryptedKey encryptedKey = cipher.encryptKey(d, key);

            // encrypt
            cipher = XMLCipher.getInstance(XMLCipher.AES_192);
            cipher.init(XMLCipher.ENCRYPT_MODE, key);
      EncryptedData builder = cipher.getEncryptedData();

      KeyInfo builderKeyInfo = builder.getKeyInfo();
      if (builderKeyInfo == null) {
        builderKeyInfo = new KeyInfo(d);
        builder.setKeyInfo(builderKeyInfo);
      }

      builderKeyInfo.add(encryptedKey);

            ed = cipher.doFinal(d, e);

            //decrypt
      key = null;
            ee = (Element) ed.getElementsByTagName("xenc:EncryptedData").item(0);
            cipher = XMLCipher.getInstance();
            cipher.init(XMLCipher.DECRYPT_MODE, null);

      EncryptedData encryptedData = cipher.loadEncryptedData(ed, ee);
     
      if(encryptedData == null) {
        System.out.println("ed is null");
      }
      else if (encryptedData.getKeyInfo() == null) {
        System.out.println("ki is null");
      }
      EncryptedKey ek = encryptedData.getKeyInfo().itemEncryptedKey(0);

      if (ek != null) {
        XMLCipher keyCipher = XMLCipher.getInstance();
        keyCipher.init(XMLCipher.UNWRAP_MODE, kek);
        key = keyCipher.decryptKey(ek, encryptedData.getEncryptionMethod().getAlgorithm());
      }

      // Create a new cipher just to be paranoid
      XMLCipher cipher3 = XMLCipher.getInstance();
      cipher3.init(XMLCipher.DECRYPT_MODE, key);
View Full Code Here

            //decrypt
            cipher = XMLCipher.getInstance(XMLCipher.TRIPLEDES);
            cipher.init(XMLCipher.DECRYPT_MODE, key);
            ee = (Element) ed.getElementsByTagName("xenc:EncryptedData").item(0);
      EncryptedData encryptedData = cipher.loadEncryptedData(ed, ee);
      Assert.assertEquals(encryptedData.getEncryptionMethod().getAlgorithm(),
                XMLCipher.TRIPLEDES);
            dd = cipher.doFinal(ed, ee);

            target = toString(dd);
      Assert.assertEquals(source, target);
View Full Code Here

      EncryptedKey encryptedKey = cipher.encryptKey(d, key);

            // encrypt
            cipher = XMLCipher.getInstance(XMLCipher.AES_128);
            cipher.init(XMLCipher.ENCRYPT_MODE, key);
      EncryptedData builder = cipher.getEncryptedData();

      KeyInfo builderKeyInfo = builder.getKeyInfo();
      if (builderKeyInfo == null) {
        builderKeyInfo = new KeyInfo(d);
        builder.setKeyInfo(builderKeyInfo);
      }

      builderKeyInfo.add(encryptedKey);

            ed = cipher.doFinal(d, e);
View Full Code Here

TOP

Related Classes of org.apache.xml.security.encryption.EncryptedData

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.