https://issues.apache.org/bugzilla/show_bug.cgi?id=52690

--- Comment #4 from Yegor Kozlov <ye...@dinom.ru> 2012-02-23 12:06:04 UTC ---
Please attach a decrypted file so that we can test your code sample.

Yegor  

(In reply to comment #3)
> Sorry, Buzilla and/or my browser lost my original description of the problem
> 
> The issue is that the classic POI 'myDecrypt' method below in general produces
> output files that are considered corrupt by Micrososft Office
> 
> If say you use MS Word to open a .docx file decrypted by this method you will
> get an error dialog saying the file is corrupt and asking if you would like
> attempt recovery (which incidentally will succeed)
> 
> The problem is that the output length is too long. Output must be truncated to
> the length specified in the input data stream and currently discarded for
> example in "EcmaDecryptor>>getDataStream(DirectoryNode dir)"
> 
>  This is the offending line
> 
>  128:       long size = dis.readLong();
> 
> The solution is to save this length in an instance variable of the class
> Decryptor so that it is accessible to user written code
> (Decryptor>>getLength()). Then myDecrypt method can then be modified to work
> correctly.
> =====
>     private void myDecrypt(String filename, String password) throws
> FileNotFoundException, IOException {
>         File inFile = new File(filename);
>         File outFile = new File(new File(filename).getParentFile(), 
> "Decrypted"
> + new File(filename).getName());
> 
>         System.err.println("Attempting to decrypt " + inFile.getAbsolutePath()
> + " to " + outFile.getAbsolutePath());
> 
>         POIFSFileSystem filesystem = new POIFSFileSystem(new
> FileInputStream(inFile));
>         EncryptionInfo info = new EncryptionInfo(filesystem);
>         Decryptor d = Decryptor.getInstance(info);
> 
>         try {
>             if (!d.verifyPassword(password)) {
>                 throw new RuntimeException("Unable to process: wrong
> password");
>             }
> 
>             InputStream dataStream = d.getDataStream(filesystem);
> 
>             OutputStream out = new FileOutputStream(outFile);
>             byte buf[] = new byte[1024];
>             int len;
>             while ((len = dataStream.read(buf)) > 0)
>                 out.write(buf, 0, len);
>             out.close();
>             dataStream.close();
> 
>         } catch (GeneralSecurityException ex) {
>             throw new RuntimeException("Unable to process encrypted document",
> ex);
>         }
>         System.err.println("Finished " + inFile.getAbsolutePath());
>     }

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org
For additional commands, e-mail: dev-h...@poi.apache.org

Reply via email to