[jdom-interest] Can file for Document be deleted?

ÁÎÃûѧ mxliao at mails.gscas.ac.cn
Wed Dec 3 08:47:45 PST 2003


Thank you very much for your warm help. I followed your way and have solved
my puzzle. Here is my real code,not including details.

1) In a class to define how to get ciphers:

  public static Cipher getDecryptCipher(String keyFilePath){}
  public static Cipher getEncryptCipher(String keyFilePath){}

2) In a document manager Class,we have a set:
  public static boolean setDoc(File catFile,Cipher cipher)
  {
    try
    {
      doc = builder.build(new CipherInputStream(
                          new FileInputStream(catFile),cipher));
    }
    catch (Exception e){}
  }
   and a function for saving Document instance:
  public static void save(String catFilePath,Cipher cipher)
  {
    try
    {
      String indent = " ";
      boolean newLines = true;
      XMLOutputter outp = new XMLOutputter(indent, newLines, "GB2312");
      outp.setTextTrim(true);
      outp.output(doc,new CipherOutputStream(
                      new FileOutputStream(catFilePath),cipher));
    }
    catch (Exception e) {}
  }

3) In the main window of my application, a method to create a JTree instance
   from an encrypted xml file is as below:
  public boolean createTree()
  {
     .................................
    if(lastFilePath.endsWith(".cat"))//which is an encrypted xml file path
    {
      try
      {
        if(!Catalog.setDoc(new File(lastFilePath),
                           CatalogCipher.getDecryptCipher(keyFilePath)))
           return false;
      }
      catch(Exception e){}
   }
4) Twinning with the above is to save JTree or Document instance to file:
 void this_windowClosing(WindowEvent e)
  {
      if(currentFilePath.toLowerCase().endsWith(".cat"))
      {
         Catalog.save(currentFilePath,
                     CatalogCipher.getEncryptCipher(keyFilePath));
      }
  }



ÔÚÄúµÄÀ´ÐÅÖÐÔø¾­Ìáµ½:
>From: Phill_Perryman at Mitel.COM
>Reply-To: 
>To: jdom-interest at jdom.org
>Subject: Re: [jdom-interest] Can file for Document be deleted?
>
>We have been using encrypted files for quite a while now and not had any 
>problems, we do not however write out  a plain file, we build directly 
>from the encrypt stream
>
>                if (encrypt == true) {
>
>                        byte[] b = { magic numbers go here };
>
>                        // Create PBE Cipher
>                        Cipher pbeCipher = createCipher(b, false);
>
>                        FileInputStream fis = new
FileInputStream(file.toString());
>                        in = new CipherInputStream(fis, pbeCipher);
>
>                } else {
>                        in = new FileInputStream(file.toString());
>                }
>                SAXBuilder builder = new SAXBuilder();
>                builder.setFactory(jdomFactory);
>                doc = builder.build(in);
>
>/Phill
>IS Dept, Software Engineer.
>phill_perryman at mitel.com
>http://www.mitel.com
>Tel: +44 1291 436023
>
>
>
>
>"ÁÎÃûѧ" <mxliao at mails.gscas.ac.cn>
>Sent by: jdom-interest-admin at jdom.org
>02/12/2003 02:57
>Please respond to "ÁÎÃûѧ"
>
> 
>        To:     jdom-interest at jdom.org
>        cc: 
>        Subject:        [jdom-interest] Can file for Document be deleted?
>
>
>Sometimes I use an encrypted(by FlowFish) xml file to construct a 
>Document.
>Firstly I decrypt the file to a plain .xml file, then extract an instance 
>of
>Document from the plain file. Generally, for the sake of security,the 
>plain file
>should be deleted. I have done it this way and all does work. But I am not 
>sure
>whether the Document instance will be somehow affected under some certain
>circumstance unknown to me.
>
>
>_______________________________________________
>To control your jdom-interest membership:
>http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
>
>





More information about the jdom-interest mailing list