Skip to content

how to add Id to KeyInfo tag ? #482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sibelius opened this issue Jan 28, 2025 · 6 comments
Closed

how to add Id to KeyInfo tag ? #482

sibelius opened this issue Jan 28, 2025 · 6 comments

Comments

@sibelius
Copy link

<ds:KeyInfo Id="key-info-id">
@srd90
Copy link

srd90 commented Jan 30, 2025

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:

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.

@sibelius
Copy link
Author

both closed issues answered with more info to help people

@srd90
Copy link

srd90 commented Feb 17, 2025

IMHO this issue can be closed because this is actually "part of" problem described at issue:

which in turn is duplicate of

@matheusinfo
Copy link

matheusinfo commented Apr 30, 2025

Hi @sibelius, have you ever succeeded in doing this?

I'm having the same problem with Signed XML.

@sibelius
Copy link
Author

Not with nodejs, we moved to Java for this

@jlucaso1
Copy link

jlucaso1 commented May 9, 2025

@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);

@sibelius sibelius closed this as completed May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants