Home > Back-end >  Java import excel when, how to verify the protection of the workbook password is correct? Pray god g
Java import excel when, how to verify the protection of the workbook password is correct? Pray god g

Time:04-02

Does anyone know the Java import excel when, how to verify the protection of the workbook password is correct?

Correct password is known, the password when I export has been set up, such as sheet, protectSheet (new String (" 123456 "));//123456 is password.

But how can I import again to verify the correctness of this password,

The diagram below:

CodePudding user response:

Great god teach genuflect is begged!!!!!!!!!!

CodePudding user response:

First check when the import correctness refers to enter a password when reading the book?

The Decryptor. GetInstance (new EncryptionInfo (new NPOIFSFileSystem (File File, Boolean readOnly))). The verifyPassword (password);


Have you ever been tampered with or to verify the password of the workbook?

Will correspond to the password stored in export, and then check when the import

CodePudding user response:

Right, it is to point to read the workbook inside data validates the workbook to protect password is correct, the correct password is known, the need of the import according to the known correct password authentication import file workbook password is correct, objective: rules can only be used when the user action by the system of export excel template, to import the data update, as shown in figure 1 and figure 2, figure a,  figure 2

CodePudding user response:

xiey_ town style reference 3 floor response:
right, refers to read the book inside data validates the workbook to protect password is correct, the correct password is known, the need of the import according to the known correct password authentication import file workbook password is correct, objective: rules can only be used when the user action by the system of export excel template, to import the data update, as shown in figure 1 and figure 2, figure a,
figure 2



This method can't use?
Boolean checkResult=the Decryptor. GetInstance (new EncryptionInfo (new NPOIFSFileSystem (new File (" "), true))). The verifyPassword (" 123456 ");
If (checkResult) {
//inspection right
}

CodePudding user response:

03 version XLS excel can

Workbook Workbook=WorkbookFactory. Create (new FileInputStream (file));
Sheet other=workbook. GetSheet (" Sheet ");

Short passwordEncode=(short) CryptoFunctions. CreateXorVerifier1 (" 123456 ");

Object _sheet=Reflections. GetFieldValue (other, "_sheet");
Object _protectionBlock=Reflections. GetFieldValue (_sheet, "_protectionBlock");
Object _passwordRecord=Reflections. GetFieldValue (_protectionBlock, "_passwordRecord");
Short field_1_password=(short) Reflections. GetFieldValue (_passwordRecord, "field_1_password");

If (passwordEncode==field_1_password) {
System. The out. Println (" password right ");
} else {
System. The out. Println (" password error ");
}
  • Related