how to add `Id` to KeyInfo tag ?
<ds:KeyInfo Id="key-info-id">
Are you aware that this repository has discussions section activated?
IMHO all of these could have been started as questions at discussions instead of issues:
- https://github.com/node-saml/xml-crypto/issues/479
- https://github.com/node-saml/xml-crypto/issues/480
- https://github.com/node-saml/xml-crypto/issues/481
- https://github.com/node-saml/xml-crypto/issues/482
- https://github.com/node-saml/xml-crypto/issues/483
Some of those issues were resolved by you with comment like "nevermind"/"got working". If you had an issue why not share solution with others who might have tried to already spend time to replicate your problem with short info that you provided.
both closed issues answered with more info to help people
IMHO this issue can be closed because this is actually "part of" problem described at issue:
- https://github.com/node-saml/xml-crypto/issues/481
which in turn is duplicate of
- https://github.com/node-saml/xml-crypto/issues/463
- which is being handled/WIP at https://github.com/node-saml/xml-crypto/pull/464
Hi @sibelius, have you ever succeeded in doing this?
I'm having the same problem with Signed XML.
Not with nodejs, we moved to Java for this
@sibelius @matheusinfo Has two way to achieve this. First one (Via Constructor Option)
const SignedXml = require("xml-crypto").SignedXml;
const fs = require("fs");
const xml = "<root><item>Some content</item></root>";
const sig = new SignedXml({
privateKey: fs.readFileSync("path/to/your/privateKey.pem"),
publicCert: fs.readFileSync("path/to/your/publicCert.pem"),
keyInfoAttributes: { Id: "key-info-id" } // Add your Id attribute here
});
// Add references, etc.
sig.addReference({
xpath: "//*[local-name(.)='item']"
});
// Compute the signature
// If you want the "ds" prefix for KeyInfo (as in <ds:KeyInfo>),
// provide it in the computeSignature options.
sig.computeSignature(xml, {
prefix: "ds" // This will make the KeyInfo tag <ds:KeyInfo>
});
const signedXml = sig.getSignedXml();
console.log(signedXml);
Second one (Via Instance Property)
const SignedXml = require("xml-crypto").SignedXml;
const fs = require("fs");
const xml = "<root><item>Some content</item></root>";
const sig = new SignedXml({
privateKey: fs.readFileSync("path/to/your/privateKey.pem"),
publicCert: fs.readFileSync("path/to/your/publicCert.pem")
});
sig.keyInfoAttributes = { Id: "key-info-id" }; // Set your Id attribute here
sig.addReference({
xpath: "//*[local-name(.)='item']"
});
sig.computeSignature(xml, {
prefix: "ds"
});
const signedXml = sig.getSignedXml();
console.log(signedXml);