验证加密文件的密码

验证加密文件的密码

要验证加密文件的密码,Aspose.Cells for .NET 提供了 VerifyPassword 方法。这些方法接受两个参数,文件流和需要验证的密码。 以下代码片段演示了使用VerifyPassword方法来验证提供的密码是否有效。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create a Stream object
FileStream fstream = new FileStream(dataDir + "EncryptedBook1.xlsx", FileMode.Open);
bool isPasswordValid = FileFormatUtil.VerifyPassword(fstream, "1234");
Console.WriteLine("Password is Valid: " + isPasswordValid);