Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

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

����ѧ

2003-12-03


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));
   }
}



�����4�������ᵽ:
>From: Phill_Perryman@(protected)
>Reply-To:
>To: jdom-interest@(protected)
>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@(protected)
>http://www.mitel.com
>Tel: +44 1291 436023
>
>
>
>
>"����ѧ" <mxliao@(protected)>
>Sent by: jdom-interest-admin@(protected)
>02/12/2003 02:57
>Please respond to "����ѧ"
>
>
>     To:   jdom-interest@(protected)
>     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@(protected)
>
>


_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@(protected)


©2008 junlu.com - Jax Systems, LLC, U.S.A.