Uploaded image for project: 'XML-RPC'
  1. XML-RPC
  2. XMLRPC-88

org.apache.xml.security.encryption.XMLCipher.removeContent

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Invalid
    • unspecified
    • None
    • Releases
    • None
    • OS:Windows 2000
      J2SE:1.5
      JRE:1.5.0_06
      Hardware: P-4 2.4 Ghz CPU, 2GB RAM.

    Description

      Hello,

      I am trying to encrypt a XML file using XMLCipher class. The size of the file is almost 35 MB, while encrypting the XML file it throws this error after around 3 minutes.
      The program works perfectly fine for file size of less than 5 MB. This is very critical for our project and has to work as soon as possible.
      Eventually we are going to port the application on AIX5.3
      The piece of code I am using is:

      public void encryptData() throws EncryptionException
      {
      final String methodName = "encryptData";

      XMLCipher keyCipher,xmlCipher = null;
      Document document = null;
      String encryptedFileName = null;
      Key symmetricKey = null;
      Key keyEncryptKey = null;
      boolean exceptionOccured = false;

      try
      {
      System.out.println("now parsing document");
      document=parseFile( fileToBeEncrypted );
      // generate symmetric key
      symmetricKey = GenerateSymmetricKey();

      // Get a key to be used for encrypting the symmetric key
      keyEncryptKey = GenerateKeyEncryptionKey();

      // Write the key to a file
      //and pass the key and the name of file in which it has to store the Key
      storeKeyFile(keyEncryptKey,getKeyFileName(fileToBeEncrypted.toString()));

      // initialize cipher and operation mode is to wrap a key
      keyCipher =XMLCipher.getInstance(XMLCipher.TRIPLEDES_KeyWrap);
      keyCipher.init(XMLCipher.WRAP_MODE, keyEncryptKey);

      // encrypt symmetric key
      EncryptedKey encryptedKey = keyCipher.encryptKey(document, symmetricKey);
      // specify the element to encrypt, ideally it will be root element
      Element rootElement = document.getDocumentElement();

      Element elementToEncrypt = rootElement;

      if (elementToEncrypt == null)

      { throw new EncryptionException("Element to Encrypt is null since the filename may not be correct" + "or the file to be encrypted may not be well formed" + "Please check in File" + "AMLFeederConfiguration.properties"); }

      // initialize cipher for encrypting XML data using operation mode of ENCRYPT_MODE
      xmlCipher = XMLCipher.getInstance(XMLCipher.TRIPLEDES);

      xmlCipher.init(XMLCipher.ENCRYPT_MODE, symmetricKey);

      // add key info to encrypted data element, so that within the encrypted data,
      // there is also information about the key, that should be used to decrypt the data
      EncryptedData encryptedDataElement = xmlCipher.getEncryptedData();
      KeyInfo keyInfo = new KeyInfo(document);
      keyInfo.add(encryptedKey);
      encryptedDataElement.setKeyInfo(keyInfo);

      Problem is caused while calling doFinal() // do the actual encryption
      boolean encryptContentsOnly = true;
      xmlCipher.doFinal(document, elementToEncrypt, encryptContentsOnly);

      //this will return xxxxx_e.xml
      encryptedFileName = getEncryptedFileNameToWrite(fileToBeEncrypted.toString());

      // write the results to a file
      writeEncryptedDocToFile(document, encryptedFileName);

      this.encryptedFileName = encryptedFileName;

      }
      catch(FileNotFoundException fnfException){

      }
      catch (ContentHandlerAlreadyRegisteredException e) {
      }
      catch(XMLEncryptionException xeException){
      }
      catch( EncryptionException encryptionException )
      {
      }
      catch(Exception e){
      }
      finally{

      if(exceptionOccured)

      { moveToRejectedDir( this.fileToBeEncrypted ); moveToRejectedDir( this.keyFile ); }

      document = null;
      symmetricKey = null;
      keyEncryptKey = null;
      xmlCipher = null;

      }

      }

      The exception I am getting is:
      Exception in thread "main" java.lang.StackOverflowError
      at org.apache.xerces.dom.ParentNode.internalRemoveChild(Unknown Source)
      at org.apache.xerces.dom.ParentNode.removeChild(Unknown Source)
      at org.apache.xml.security.encryption.XMLCipher.removeContent(Unknown So
      urce)
      at org.apache.xml.security.encryption.XMLCipher.removeContent(Unknown So
      urce)
      at org.apache.xml.security.encryption.XMLCipher.removeContent(Unknown So
      urce)
      at org.apache.xml.security.encryption.XMLCipher.removeContent(Unknown So
      urce)
      at org.apache.xml.security.encryption.XMLCipher.removeContent(Unknown So
      urce)
      at org.apache.xml.security.encryption.XMLCipher.removeContent(Unknown So
      urce)
      at org.apache.xml.security.encryption.XMLCipher.removeContent(Unknown So
      urce)
      at org.apache.xml.security.encryption.XMLCipher.removeContent(Unknown So
      urce)
      at org.apache.xml.security.encryption.XMLCipher.removeContent(Unknown So

      Attachments

        Activity

          People

            Unassigned Unassigned
            arpitd Arpit Doshi
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: