Skip to content

Instantly share code, notes, and snippets.

@yaronn
Last active December 18, 2015 23:19
Show Gist options
  • Save yaronn/5860880 to your computer and use it in GitHub Desktop.
Save yaronn/5860880 to your computer and use it in GitHub Desktop.
var crypto = require('xml-crypto')
, Dom = require('xmldom').DOMParser
, fs = require('fs')
var xml = fs.readFileSync('./windows_store_signature.xml', 'utf-8');
var doc = new Dom({ignoreWhiteSpace: true}).parseFromString(xml);
xml = doc.firstChild.toString()
var signature = crypto.xpath(doc, "//*//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0];
var sig = new crypto.SignedXml();
sig.keyInfoProvider = new crypto.FileKeyInfo("./windows_store_certificate.pem");
sig.loadSignature(signature.toString());
var result = sig.checkSignature(xml);
if (result)
console.log("signature is valid")
else
console.log("signature is invalid: " + sig.validationErrors)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment