暗号化されたファイルのパスワードを確認する
Contents
[
Hide
]
Excel(xlsx、xlsb、xls、xlsm)およびOpen Office(ODS)ファイルがパスワードでロックされている場合、Asposeはファイルの特定のデータを解析せずに簡単なパスワード検証をサポートしています。
暗号化されたファイルのパスワードを確認します
Aspose.Cells for .NETは、暗号化されたファイルのパスワードを検証するためのVerifyPasswordメソッドを提供します。これらのメソッドは、ファイルストリームと検証する必要があるパスワードの2つのパラメータを受け入れます。 以下のコードスニペットは、提供されたパスワードが有効かどうかを確認するVerifyPasswordメソッドの使用を示しています。
This file contains 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-.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); |