Verify Password of Encrypted Files with C++
Contents
[
Hide
]
If Excel (xlsx, xlsb, xls, xlsm) and Open office (ODS) files are locked with a password, Aspose supports simple password verification without parsing specific data of the files.
Verify the password of the encrypted file
To verify the password of the encrypted file, Aspose.Cells for C++ provides the VerifyPassword method. This method accepts two parameters, the file stream and the password that needs to be verified. The following code snippet demonstrates the use of the VerifyPassword method to verify whether the provided password is valid or not.
#include <iostream>
#include <fstream>
#include <vector>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
U16String inputPath = srcDir + u"EncryptedBook1.xlsx";
std::vector<uint8_t> fileData;
std::ifstream file(inputPath.ToUtf8(), std::ios::binary);
if (file)
{
file.seekg(0, std::ios::end);
fileData.resize(file.tellg());
file.seekg(0, std::ios::beg);
file.read(reinterpret_cast<char*>(fileData.data()), fileData.size());
}
Vector<uint8_t> data(fileData.data(), static_cast<int32_t>(fileData.size()));
bool isPasswordValid = FileFormatUtil::VerifyPassword(data, u"123456");
std::cout << "Password is Valid: " << std::boolalpha << isPasswordValid << std::endl;
Aspose::Cells::Cleanup();
}