-
Notifications
You must be signed in to change notification settings - Fork 49
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
How to sign KeyInfo? #69
Comments
You can do it programmatically before const xmlsig = new XmlDSigJs.SignedXml();
// Set Id for KeyInfo
xmlsig.XmlSignature.KeyInfo.Id = "KeyInfo001";
// Create Reference for KeyInfo
const keyInfoRef = new XmlDSigJs.Reference("#KeyInfo001");
keyInfoRef.DigestMethod.Algorithm = XmlDSigJs.SHA1_NAMESPACE;
// Add Reference to SignedInfo
xmlsig.XmlSignature.SignedInfo.References.Add(keyInfoRef); |
This is source code for Reference creation from options |
@microshine, thanks for your reply.
Now I get the following error when 'npm run build'
src/index.ts → dist/xades.js...
(!) Missing exports
https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module
src/signed_xml.ts
SHA1_NAMESPACE is not exported by node_modules/xmldsigjs/lib/index.js
2018-05-25 0:49 GMT-06:00 Miroshin Stepan <notifications@github.com>:
… You can do it programmatically before Sign method calling.
// Set Id for KeyInfothis.XmlSignature.KeyInfo.Id = "KeyInfo001";
// Create Reference for KeyInfoconst keyInfoRef = new XmlDSigJs.Reference("#KeyInfo001");keyInfoRef.DigestMethod.Algorithm = XmlDSigJs.SHA1_NAMESPACE;
// Add Reference to SignedInfothis.XmlSignature.SignedInfo.References.Add(keyInfoRef);
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#69 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AQpy2vIohFzrSlaOJw5kezU-bbmGhKC6ks5t16ljgaJpZM4UNGlc>
.
|
This is my error. You can use |
When trying to sign the document the following error occurs. XmlError { |
Can you fix it and make PR? I don't have enough time to fix it right now. I have to finish some tasks in another project |
Hi all, |
I published new version of Here is example for Id adding to const XmlDSigJs = require("xmldsigjs");
const CryptoOssl = require("node-webcrypto-ossl");
const crypto = new CryptoOssl();
XmlDSigJs.Application.setEngine("OpenSSL", crypto);
async function main() {
const xml = `<root><child/></root>`;
const xmlsig = new XmlDSigJs.SignedXml();
const alg = {
name: "RSASSA-PKCS1-v1_5",
hash: "SHA-256",
publicExponent: new Uint8Array([1, 0, 1]),
modulusLength: 2048,
};
const keys = await crypto.subtle.generateKey(alg, false, ["sign", "verify"]);
// Set Id for <Signature>
xmlsig.XmlSignature.Id = "Signature001";
// Set Id for <KeyInfo>
xmlsig.XmlSignature.KeyInfo.Id = "KeyInfo001";
// Create <Reference> for <KeyInfo>
const keyInfoRef = new XmlDSigJs.Reference("#KeyInfo001");
keyInfoRef.DigestMethod.Algorithm = XmlDSigJs.SHA256_NAMESPACE;
// Create <Reference> for #Document
const docRef = new XmlDSigJs.Reference("");
keyInfoRef.DigestMethod.Algorithm = XmlDSigJs.SHA256_NAMESPACE;
// Add <Reference>s to <SignedInfo>
xmlsig.XmlSignature.SignedInfo.References.Add(keyInfoRef);
xmlsig.XmlSignature.SignedInfo.References.Add(docRef);
// Add <KeyValue>
const keyValue = new XmlDSigJs.KeyValue();
await keyValue.importKey(keys.publicKey);
xmlsig.XmlSignature.KeyInfo.Add(keyValue)
await xmlsig.Sign( // Signing document
alg, // algorithm
keys.privateKey, // key
XmlDSigJs.Parse(xml), // document)
);
console.log(xmlsig.toString()); // <xml> document with signature
}
main().catch((err) => console.log(err)); Output XML
|
Many thanks for the excellent help. Now even KeyInfo is being signed. I just need to be able to set the Id of the SignatureValue, as in the following example:
|
How to sign the KeyInfo (#KeyInfo001), which is part of the signature element itself?
The text was updated successfully, but these errors were encountered: