xml-crypto是一个Node.js的扩展用来实现对XML数据签名和加密。
示例代码:
varSignedXml=require('xml-crypto').SignedXml,FileKeyInfo=require('xml-crypto').FileKeyInfo,fs=require('fs')varxml="<library>"+"<book>"+"<name>HarryPotter</name>"+"</book>""</library>"varsig=newSignedXml()sig.addReference("//*[local-name(.)='book']")sig.signingKey=fs.readFileSync("client.pem")sig.computeSignature(xml)fs.writeFileSync("signed.xml",sig.getSignedXml())
评论