You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When signing a xml document you can specify the following properties on a `SignedXml` instance to customize the signature process:
69
69
70
70
-`sign.signingKey` - **[required]** a `Buffer` or pem encoded `String` containing your private key
71
-
-`sign.keyInfoProvider` - **[optional]** a key info provider instance, see [customizing algorithms](#customizing-algorithms) for an implementation example
72
71
-`sign.signatureAlgorithm` - **[optional]** one of the supported [signature algorithms](#signature-algorithms). Ex: `sign.signatureAlgorithm = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"`
73
72
-`sign.canonicalizationAlgorithm` - **[optional]** one of the supported [canonicalization algorithms](#canonicalization-and-transformation-algorithms). Ex: `sign.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#WithComments"`
74
73
@@ -119,7 +118,9 @@ To generate a `<X509Data></X509Data>` element in the signature you must provide
119
118
120
119
When verifying a xml document you must specify the following properties on a ``SignedXml` instance:
121
120
122
-
-`sign.keyInfoProvider` - **[required]** a key info provider instance containing your certificate, see [customizing algorithms](#customizing-algorithms) for an implementation example
121
+
-`sign.signingCert` - **[optional]** your certificate as a string, a string of multiple certs in PEM format, or a Buffer, see [customizing algorithms](#customizing-algorithms) for an implementation example
122
+
123
+
The certificate that will be used to check the signature will first be determined by calling `.getCertFromKeyInfo()`, which function you can customize as you see fit. If that returns `null`, then `.signingCert` is used. If that is `null`, then `.signingKey` is used (for symmetrical signing applications).
123
124
124
125
You can use any dom parser you want in your code (or none, depending on your usage). This sample uses [xmldom](https://github.com/jindw/xmldom) so you should install it first:
125
126
@@ -133,7 +134,6 @@ Example:
133
134
var select =require("xml-crypto").xpath,
134
135
dom =require("@xmldom/xmldom").DOMParser,
135
136
SignedXml =require("xml-crypto").SignedXml,
136
-
FileKeyInfo =require("xml-crypto").FileKeyInfo,
137
137
fs =require("fs");
138
138
139
139
var xml =fs.readFileSync("signed.xml").toString();
@@ -144,7 +144,7 @@ var signature = select(
144
144
"//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']"
-`checkSignature(xml)` - validates the given xml document and returns true if the validation was successful, `sig.validationErrors` will have the validation errors if any, where:
233
233
-`xml` - a string containing a xml document
234
234
235
-
### FileKeyInfo
236
-
237
-
A basic key info provider implementation using `fs.readFileSync(file)`, is constructed using `new FileKeyInfo([file])` where:
238
-
239
-
-`file` - a path to a pem encoded certificate
240
-
241
-
See [verifying xml documents](#verifying-xml-documents) for an example usage
242
-
243
235
## Customizing Algorithms
244
236
245
237
The following sample shows how to sign a message using custom algorithms.
@@ -253,24 +245,15 @@ var SignedXml = require("xml-crypto").SignedXml,
253
245
254
246
Now define the extension point you want to implement. You can choose one or more.
255
247
256
-
A key info provider is used to extract and construct the key and the KeyInfo xml section.
257
-
Implement it if you want to create a signature with a KeyInfo section, or you want to read your key in a different way then the default file read option.
248
+
To determine the inclusion and contents of a `<KeyInfo />` element, the function
249
+
`getKeyInfoContent()` is called. There is a default implementation of this. If you wish to change
250
+
this implementation, provide your own function assigned to the property `.getKeyInfoContent`. If
251
+
there are no attributes and no contents to the `<KeyInfo />` element, it won't be included in the
* @param cert the certificate as a string or array of strings (see https://www.w3.org/TR/2008/REC-xmldsig-core-20080610/#sec-X509Data)
135
+
* @param prefix an optional namespace alias to be used for the generated XML
136
+
*/
137
+
exportinterfaceGetKeyInfoContentArgs{
138
+
cert: string|string[]|Buffer;
139
+
prefix: string;
140
+
}
141
+
132
142
exportclassSignedXml{
133
143
// To add a new transformation algorithm create a new class that implements the {@link TransformationAlgorithm} interface, and register it here. More info: {@link https://github.com/node-saml/xml-crypto#customizing-algorithms|Customizing Algorithms}
// To add a new hash algorithm create a new class that implements the {@link HashAlgorithm} interface, and register it here. More info: {@link https://github.com/node-saml/xml-crypto#customizing-algorithms|Customizing Algorithms}
// To add a new signature algorithm create a new class that implements the {@link SignatureAlgorithm} interface, and register it here. More info: {@link https://github.com/node-saml/xml-crypto#customizing-algorithms|Customizing Algorithms}
0 commit comments