使用Node.js通过C++验证加密文件的密码

验证加密文件的密码

为了验证加密文件的密码,Aspose.Cells for Node.js via C++提供了FileFormatUtil.verifyPassword(Uint8Array, string)方法。该方法接受两个参数:文件流和需要验证的密码。
以下代码片段演示了使用FileFormatUtil.verifyPassword(Uint8Array, string)方法来验证提供的密码是否有效。

const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "EncryptedBook1.xlsx");

// Create a Stream object
const fs = require("fs");
const fstream = fs.readFileSync(filePath);

const isPasswordValid = AsposeCells.FileFormatUtil.verifyPassword(fstream, "1234");

console.log("Password is Valid: " + isPasswordValid);