验证加密文件的密码
Contents
[
Hide
]
如果Excel(xlsx、xlsb、xls、xlsm)和Open office(ODS)文件被密码锁定,Aspose.Cells for Java支持简单的密码验证,无需解析文件的具体数据。
验证加密文件的密码
验证加密文件密码,Aspose.Cells for Java提供[验证密码](https://reference.aspose.com/cells/java/com.aspose.cells/fileformatutil#verifyPassword(java.io.InputStream,%20java.lang.String)) 方法。该方法接受两个参数,文件流和需要验证的密码。 下面的代码片段演示了使用[验证密码](https://reference.aspose.com/cells/java/com.aspose.cells/fileformatutil#verifyPassword(java.io.InputStream,%20java.lang.String)方法来验证提供的密码是否有效。
示例代码:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(VerifyPassword.class) + "LoadingSavingConvertingAndManaging/"; | |
// Create a Stream object | |
FileInputStream fstream = new FileInputStream(dataDir + "EncryptedBook1.xlsx"); | |
boolean isPasswordValid = FileFormatUtil.verifyPassword(fstream, "1234"); | |
System.out.println("Password is Valid: " + isPasswordValid); |