Skip to content

Instantly share code, notes, and snippets.

@c0rp-aubakirov
Created September 29, 2018 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c0rp-aubakirov/75098e5a0744dcbbff5d35de62ba78dd to your computer and use it in GitHub Desktop.
Save c0rp-aubakirov/75098e5a0744dcbbff5d35de62ba78dd to your computer and use it in GitHub Desktop.
var SignedXml = require('xml-crypto').SignedXml
, fs = require('fs')
var xml = `<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><certificateNumber xmlns="https://allpay.kz">27</certificateNumber></soap:Header><soap:Body><ns2:createCashInTransaction xmlns:ns2="http://www.allpay.kz/mfs/soap/TransactionManagement/1.1"><CashInRequest><header><lang>ru</lang><timestamp>2018-08-10T19:04:11.385+06:00</timestamp><requester>10124213</requester></header><toUserName>77072734954</toUserName><amount>10</amount><GUID>fa495ffa-4825-485e-9b14-a04c6d8315d2</GUID></CashInRequest></ns2:createCashInTransaction></soap:Body></soap:Envelope>`
var sig = new SignedXml(null)
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#WithComments"
sig.addReference(
// reference to the root node
"/*",
[
'http://www.w3.org/2000/09/xmldsig#enveloped-signature'
],
'http://www.w3.org/2000/09/xmldsig#sha1',
'',
'',
'',
// let the URI attribute with an empty value,
// this is the signal that the signature is affecting the whole xml document
true
);
sig.signingKey = fs.readFileSync("client.pem")
sig.computeSignature(xml)
fs.writeFileSync("signed.xml", sig.getSignedXml())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment