You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Пестов Алексей <pe...@gmail.com> on 2013/05/16 17:10:22 UTC

Cyrillic password on XLS.

Hi all!
I set a cyrillic password "ййй" on excelFile.xls file.

My code:

*import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;import
org.apache.poi.hssf.usermodel.HSSFWorkbook;import
org.apache.poi.ss.usermodel.Workbook;
import java.io.*;
public class PasswordFileTest {
    public static void main(String[] args) throws IOException {

        File xlsFile = new File("C:\\excelFile.xls");

        try (InputStream is = new FileInputStream(xlsFile)) {

            Biff8EncryptionKey.setCurrentUserPassword("ййй");
            Workbook book = new HSSFWorkbook(is);
            System.out.println("Password ok!");

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    } *

*}*

and what I get:

*Exception in thread "main" org.apache.poi.EncryptedDocumentException:
Supplied password is invalid for docId/saltData/saltHash
	at org.apache.poi.hssf.record.RecordFactoryInputStream$StreamEncryptionInfo.createDecryptingStream(RecordFactoryInputStream.java:116)
	at org.apache.poi.hssf.record.RecordFactoryInputStream.<init>(RecordFactoryInputStream.java:184)
	at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:440)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:285)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:248)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:192)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:327)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:308)
	at PasswordFileTest.main(PasswordFileTest.java:20)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601) *

* at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) *
*
*
Is this supported by POI 3.8 ?



-- 
С уважением,
Алексей Пестов
тел. +7 (925) 067-32-13

Re: Cyrillic password on XLS.

Posted by Nick Burch <ap...@gagravarr.org>.
On Thu, 16 May 2013, Пестов Алексей wrote:
> I set a cyrillic password "ййй" on excelFile.xls file.

You need to ensure the encoding that javac reads your .java file in 
matches the one you wrote the non-ascii characters in. Might be safest 
initially to write them in the unicode escaped form (\u...) so you're sure 
they don't get corrupted

Nick