Package org.apache.xml.security.encryption

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


      Key key = keygen.generateKey();

           
            cipher = XMLCipher.getInstance(XMLCipher.RSA_v1dot5);
      cipher.init(XMLCipher.WRAP_MODE, pub);
      EncryptedKey encryptedKey = cipher.encryptKey(d, key);

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


      keygen.init(192);
      Key key = keygen.generateKey();

            cipher = XMLCipher.getInstance(XMLCipher.TRIPLEDES_KeyWrap);
      cipher.init(XMLCipher.WRAP_MODE, kek);
      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());
View Full Code Here

       
        NodeList ekList = document.getElementsByTagNameNS
      (EncryptionConstants.EncryptionSpecNS,
       EncryptionConstants._TAG_ENCRYPTEDKEY);
        for (int i = 0; i < ekList.getLength(); i++) {
            EncryptedKey ek = keyCipher.loadEncryptedKey
    (document, (Element) ekList.item(i));
      assertNotNull(ek.getRecipient());
        }
    }
View Full Code Here

        }
        return secretKey;
    }

    private void embedKeyInfoInEncryptedData(Document document, XMLCipher keyCipher, XMLCipher xmlCipher, Key dataEncryptionkey) throws XMLEncryptionException {
        EncryptedKey encryptedKey = keyCipher.encryptKey(document, dataEncryptionkey);
        KeyInfo keyInfo = new KeyInfo(document);
        keyInfo.add(encryptedKey);
        EncryptedData encryptedDataElement = xmlCipher.getEncryptedData();
        encryptedDataElement.setKeyInfo(keyInfo);
    }
View Full Code Here

        }
        return secretKey;
    }

    private void embedKeyInfoInEncryptedData(Document document, XMLCipher keyCipher, XMLCipher xmlCipher, Key dataEncryptionkey) throws XMLEncryptionException {
        EncryptedKey encryptedKey = keyCipher.encryptKey(document, dataEncryptionkey);
        KeyInfo keyInfo = new KeyInfo(document);
        keyInfo.add(encryptedKey);
        EncryptedData encryptedDataElement = xmlCipher.getEncryptedData();
        encryptedDataElement.setKeyInfo(keyInfo);
    }
View Full Code Here

    }

    private void embedKeyInfoInEncryptedData(Document document, XMLCipher keyCipher, XMLCipher xmlCipher, Key dataEncryptionkey)
        throws XMLEncryptionException {

        EncryptedKey encryptedKey = keyCipher.encryptKey(document, dataEncryptionkey);
        KeyInfo keyInfo = new KeyInfo(document);
        keyInfo.add(encryptedKey);   
        EncryptedData encryptedDataElement = xmlCipher.getEncryptedData();
        encryptedDataElement.setKeyInfo(keyInfo);
    }
View Full Code Here

    }

    private void embedKeyInfoInEncryptedData(Document document, XMLCipher keyCipher, XMLCipher xmlCipher, Key dataEncryptionkey)
        throws XMLEncryptionException {

        EncryptedKey encryptedKey = keyCipher.encryptKey(document, dataEncryptionkey);
        KeyInfo keyInfo = new KeyInfo(document);
        keyInfo.add(encryptedKey);   
        EncryptedData encryptedDataElement = xmlCipher.getEncryptedData();
        encryptedDataElement.setKeyInfo(keyInfo);
    }
View Full Code Here

        Key dek = options.getDataEncryptionKey();
        Key kek = options.getKeyEncryptionKey();
        String dalg = options.getDataCipherAlgorithm();
        String kalg = options.getKeyCipherAlgorithm();
        boolean includeki = options.includeKeyInfo();
        EncryptedKey enckey = null;
        XMLCipher xmlCipher = XMLCipher.getInstance(dalg);
        xmlCipher.init(XMLCipher.ENCRYPT_MODE, dek);
        if (includeki && kek != null && dek != null) {
          XMLCipher keyCipher = XMLCipher.getInstance(kalg);
          keyCipher.init(XMLCipher.WRAP_MODE, kek);
View Full Code Here

            Key dek = options.getDataEncryptionKey();
            Key kek = options.getKeyEncryptionKey();
            String dalg = options.getDataCipherAlgorithm();
            String kalg = options.getKeyCipherAlgorithm();
            boolean includeki = options.includeKeyInfo();
            EncryptedKey enckey = null;
            XMLCipher xmlCipher = XMLCipher.getInstance(dalg);
            xmlCipher.init(XMLCipher.ENCRYPT_MODE, dek);
            if (includeki && kek != null && dek != null) {
                XMLCipher keyCipher = XMLCipher.getInstance(kalg);
                keyCipher.init(XMLCipher.WRAP_MODE, kek);
View Full Code Here

        String keyType = ctx.getKeyType();
        WSTrustVersion wstVer = (WSTrustVersion)ctx.getOtherProperties().get(IssuedTokenContext.WS_TRUST_VERSION);
        if (wstVer.getSymmetricKeyTypeURI().equals(keyType)){
            final byte[] key = ctx.getProofKey();
            try{
                final EncryptedKey encKey = WSTrustUtil.encryptKey(doc, key, (X509Certificate)ctx.getOtherProperties().get(IssuedTokenContext.TARGET_SERVICE_CERTIFICATE), null);
                 keyInfo.add(encKey);
            } catch (Exception ex) {
                 log.log(Level.SEVERE,
                            LogStringsMessages.WST_0040_ERROR_ENCRYPT_PROOFKEY(appliesTo), ex);
                 throw new WSTrustException(LogStringsMessages.WST_0040_ERROR_ENCRYPT_PROOFKEY(appliesTo), ex);
View Full Code Here

TOP

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

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.