-
Notifications
You must be signed in to change notification settings - Fork 475
/
xml-signing-example.js
47 lines (34 loc) · 1018 Bytes
/
xml-signing-example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// This will help generate signing info for test cases.
// Simply fill in the data and run it to get <DigestValue /> and <SignatureValue />.
const crypto = require("crypto");
const private_key = `-----BEGIN PRIVATE KEY-----
-----END PRIVATE KEY-----
`;
const cert = `-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
`;
const saml_message = ``;
const signed_info = `<SignedInfo...</SignedInfo>`;
const signer = crypto.createSign("RSA-SHA1");
signer.update(signed_info);
signer.end();
const signature = signer.sign(private_key);
const signature_b64 = signature.toString("base64");
const verifier = crypto.createVerify("RSA-SHA1");
verifier.update(signed_info);
verifier.end();
const verified = verifier.verify(cert, signature);
const hash = crypto.createHash("RSA-SHA1");
hash.update(saml_message, "utf8");
const digest_b64 = hash.digest("base64");
console.log(
JSON.stringify(
{
signature: signature_b64,
digest: digest_b64,
verified: verified,
},
null,
2,
),
);