Examples of EncryptedKey


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

        XMLCipher cipher = XMLCipher.getInstance(XMLCipher.SEED_128_KeyWrap);
        keygen = KeyGenerator.getInstance("SEED");
        keygen.init(128);
        SecretKey keyWrappingKey = keygen.generateKey();
        cipher.init(XMLCipher.WRAP_MODE, keyWrappingKey);
        EncryptedKey encryptedKey = cipher.encryptKey(document, key);
       
        // Encrypt using DOM
        List<String> localNames = new ArrayList<String>();
        localNames.add("PaymentInfo");
       
View Full Code Here

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

      //Encrypt
      XMLCipher cipher = XMLCipher.getInstance(algorithms.get("aes-128").xmlSecName);
      cipher.init(XMLCipher.ENCRYPT_MODE, secretKey);

      //Encrypted Key
      EncryptedKey ekey = XMLEncryptionUtil.encryptKey(document, secretKey, publicKey, keySize);
      //Encrypted Data
      String encryptionAlgorithm = XMLEncryptionUtil.getXMLEncryptionURL(secretKey.getAlgorithm(), keySize);
      //Encrypt the Document
      cipher = XMLCipher.getInstance(encryptionAlgorithm);
      cipher.init(XMLCipher.ENCRYPT_MODE, secretKey);
View Full Code Here

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

         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)
      {
View Full Code Here

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

      if (isEncryptedKey) {
      log.debug("Passed an Encrypted Key");
      try {
        XMLCipher cipher = XMLCipher.getInstance();
        cipher.init(XMLCipher.UNWRAP_MODE, _kek);
        EncryptedKey ek = cipher.loadEncryptedKey(element);
        _key = cipher.decryptKey(ek, _algorithm);
      }
      catch (Exception e) {}
      }
   
View Full Code Here

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

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

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

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

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

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

      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

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

   private void wrap(Key k, char[] password) {

      try {
         Key wrapKey = createWrapKey(EncryptionConstants.ALGO_ID_KEYWRAP_AES256,
                                     password);
         EncryptedKey ek =
            new EncryptedKey(this._doc,
                             EncryptionConstants.ALGO_ID_KEYWRAP_AES256, null,
                             null, k, wrapKey, null, null, null, null, null,
                             null);

         /*
         String JCAalgo = k.getAlgorithm();
         String JCAformat = k.getFormat();
         String keyType = null;
         if (JavaUtils.implementsInterface(k, "java.security.PrivateKey")) {
            keyType = "PrivateKey";
         } else if (JavaUtils
                 .implementsInterface(k, "javax.crypto.SecretKey")) {
            keyType = "SecretKey";
         }
         */
         this._constructionElement.appendChild(ek.getElement());
         XMLUtils.addReturnToElement(this._constructionElement);
      } catch (XMLSecurityException ex) {
         throw new RuntimeException(ex.getMessage());
      }
   }
View Full Code Here

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

           throws NoSuchAlgorithmException, UnrecoverableKeyException {

      try {
         Key wrapKey = createWrapKey(EncryptionConstants.ALGO_ID_KEYWRAP_AES256,
                                     password);
         EncryptedKey ek =
            new EncryptedKey(this
               .getChildElementLocalName(0, EncryptionConstants
               .EncryptionSpecNS, EncryptionConstants._TAG_ENCRYPTEDKEY), this
                  ._baseURI);

         return ek.unwrap(wrapKey, EncryptionConstants.ALGO_ID_KEYWRAP_AES128);
      } catch (XMLSecurityException ex) {
         throw new RuntimeException(ex.getMessage());
      }
   }
View Full Code Here

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

        if (wrappingCert != null) {
            XMLCipher newCipher = XMLCipher.getInstance(keyTransportAlgorithm);
            newCipher.init(XMLCipher.WRAP_MODE, wrappingCert.getPublicKey());

            EncryptedKey encryptedKey = newCipher.encryptKey(document, encryptingKey);
            // Create a KeyInfo for the EncryptedKey
            KeyInfo encryptedKeyKeyInfo = encryptedKey.getKeyInfo();
            if (encryptedKeyKeyInfo == null) {
                encryptedKeyKeyInfo = new KeyInfo(document);
                encryptedKeyKeyInfo.getElement().setAttributeNS(
                    "http://www.w3.org/2000/xmlns/", "xmlns:dsig", "http://www.w3.org/2000/09/xmldsig#"
                );
                encryptedKey.setKeyInfo(encryptedKeyKeyInfo);
            }

            SecurityTokenReference securityTokenReference = new SecurityTokenReference(document);
            securityTokenReference.addWSSENamespace();
            securityTokenReference.setKeyIdentifierSKI(wrappingCert, null);
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.