Skip to content

Instantly share code, notes, and snippets.

@ediskandarov
Created April 9, 2023 18:29
Show Gist options
  • Save ediskandarov/2ecd33a16ac73fda04279d6b83d8b888 to your computer and use it in GitHub Desktop.
Save ediskandarov/2ecd33a16ac73fda04279d6b83d8b888 to your computer and use it in GitHub Desktop.
node cades script example that verifies attached signature
// Compile node module first `https://github.com/boriborm/cryptopro-node-cades`
const fs = require("node:fs");
const cades = require("./NodeCades");
const signedData = new cades.SignedData();
const message = fs.readFileSync("message.txt", { encoding: "utf-8" });
signedData.content = message; // string
const signatureRaw = fs.readFileSync("message.txt.sig"); // buffer
signedData.verifyCades(signatureRaw, cades.CADESCOM_CADES_X_LONG_TYPE_1);
console.log("verified");
console.log("Content", signedData.content);
console.log("Number of signers", signedData.signers.length);
for (const signer of signedData.signers) {
const signerCert = signer.certificate;
console.log("signer", signerCert.subjectName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment