Skip to content

Instantly share code, notes, and snippets.

@yaronn
Created May 20, 2012 16:44
Show Gist options
  • Save yaronn/2758734 to your computer and use it in GitHub Desktop.
Save yaronn/2758734 to your computer and use it in GitHub Desktop.
var select = require('xml-crypto').xpath.SelectNodes
, dom = require('xmldom').DOMParser
, SignedXml = require('xml-crypto').SignedXml
, FileKeyInfo = require('xml-crypto').FileKeyInfo
, fs = require('fs')
var xml = fs.readFileSync("signed.xml").toString()
var doc = new dom().parseFromString(xml)
var signature = select(doc, "/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0]
var sig = new SignedXml()
sig.keyInfoProvider = new FileKeyInfo("client_public.pem")
sig.loadSignature(signature.toString())
var res = sig.checkSignature(xml)
if (!res) console.log(sig.validationErrors)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment