Package org.apache.xml.security.encryption

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


             * Forth step: encrypt data, and set neccessary attributes in
             * xenc:EncryptedData
             */
            try {
                xmlCipher.init(XMLCipher.ENCRYPT_MODE, secretKey);
                EncryptedData encData = xmlCipher.getEncryptedData();
                encData.setId(xencEncryptedDataId);
                encData.setKeyInfo(keyInfo);
                xmlCipher.doFinal(doc, body, content);
            } catch (Exception e2) {
                throw new WSSecurityException(
                        WSSecurityException.FAILED_ENC_DEC, null, null, e2);
            }
View Full Code Here


        dataCipher.init(XMLCipher.ENCRYPT_MODE, secretKey);

        KeyInfo keyInfo = new KeyInfo(doc);
        keyInfo.addKeyName("mykey");

        EncryptedData encryptedData = dataCipher.getEncryptedData();
        encryptedData.setKeyInfo(keyInfo);
       
        for (int i = 0; i < dataToEncrypt.getLength(); i++) {
            dataCipher.doFinal(doc,(Element) dataToEncrypt.item(i), true);
        }
View Full Code Here

        XPathFactory xpf = XPathFactory.newInstance();
        XPath xpath = xpf.newXPath();
        xpath.setNamespaceContext(new DSNamespaceContext());

        EncryptedData builder = cipher.getEncryptedData();
        KeyInfo builderKeyInfo = builder.getKeyInfo();
        if (builderKeyInfo == null) {
            builderKeyInfo = new KeyInfo(document);
            builder.setKeyInfo(builderKeyInfo);
        }
        builderKeyInfo.add(encryptedKey);

        for (String localName : localNames) {
            String expression = "//*[local-name()='" + localName + "']";
View Full Code Here

      if(keyEL == null)
         throw new IllegalStateException("Encrypted Key not found");
     
      XMLCipher cipher =  XMLCipher.getInstance();
      cipher.init(XMLCipher.DECRYPT_MODE, null);
      EncryptedData encryptedData =  cipher.loadEncryptedData(encryptedDoc, (Element)dataEL)
      EncryptedKey encryptedKey =  cipher.loadEncryptedKey(encryptedDoc, (Element)keyEL);
     
      Document decryptedDoc = null;
     
      if (encryptedData != null && encryptedKey != null)
      {
         String encAlgoURL = encryptedData.getEncryptionMethod().getAlgorithm();
         XMLCipher keyCipher =  XMLCipher.getInstance();
         keyCipher.init(XMLCipher.UNWRAP_MODE, privateKey);
         Key encryptionKey =  keyCipher.decryptKey( encryptedKey, encAlgoURL );
         cipher =  XMLCipher.getInstance()
         cipher.init(XMLCipher.DECRYPT_MODE, encryptionKey);
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

            //decrypt
            cipher = XMLCipher.getInstance(XMLCipher.AES_128);
            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_128);
            dd = cipher.doFinal(ed, ee);

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

            //decrypt
            cipher = XMLCipher.getInstance(XMLCipher.AES_192);
            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_192);
            dd = cipher.doFinal(ed, ee);

            target = toString(dd);
      Assert.assertEquals(source, target);
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.