|
| |
There are two main modes of operation for the libraries. Signing and
verifying. Verifying is the simplest operation, as it (generally)
operates on a DOM <Signature> structure that has already been created.
Signing on the other hand can be more difficult, as there may be a
requirement to create the DOM structure necessary for the signature
prior to the actual signing operation.
The rest of this section provides a very high level overview on how
to use the library for signing and verificataion of signatures.
Two samples are provided :
The code snippets are taken directly from some of the sample code
provided in the src/samples directory in the distribution. More
information on the API can be found in the API Documentation.
|
| | | | A simple HMAC Signing example | | | | |
| |
The first example is based on the simpleHMAC.cpp code in samples. It
creates an XML letter, the appends a dummy signature to the end, using
an enveloped-signature transform.
| |
The following code snippet initialises Xerces, Xalan and XSEC.
Note that the enveloped transform is implemented using an XPath
expression, so it is imperitive the Xalan libraries are initialised.
| | | |
int main (int argc, char **argv) {
try {
XMLPlatformUtils::Initialize();
#ifndef XSEC_NO_XALAN
XalanTransformer::initialize();
#endif
XSECPlatformUtils::Initialise();
}
catch (const XMLException &e) {
cerr << "Error during initialisation of Xerces" << endl;
cerr << "Error Message = : "
<< e.getMessage() << endl;
}
// Create a blank Document
DOMImplementation *impl =
DOMImplementationRegistry::getDOMImplementation(MAKE_UNICODE_STRING("Core"));
// Create a letter
DOMDocument *doc = createLetter(impl);
DOMElement *rootElem = doc->getDocumentElement();
| | | | |
In the sample application, the call to createLetter(impl)
simply creates a
letter DOM structure with a to and from address and some text.
This is done using standard DOM calls via Xerces.
Once the system is initialised and the DOM document is created,
a DSIGSignature object is created via the XSECProvider
interface class. The signature object is then used to create
a blank signature DOM node structure which is then inserted at
the end of the document.
| | | |
XSECProvider prov;
DSIGSignature *sig;
DOMElement *sigNode;
try {
// Create a signature object
sig = prov.newSignature();
sig->setDSIGNSPrefix("ds");
// Use it to create a blank signature DOM structure from the doc
sigNode = sig->createBlankSignature(doc,
CANON_C14N_COM,
SIGNATURE_HMAC,
HASH_SHA1);
| | | | |
The call to newSignature creates a signature
object only. No DOM nodes are created at this point.
The call to setDSIGNSPrefix tells the XSEC
library what namespace prefix to use for the signature object when
it starts to create DOM nodes (in this case "ds" will be used).
By default, the library will use "dsig" as the prefix for the name
space for Digital Signatures.
Finally, the call to sig->createBlankSignature sets up both the
DOM structure and the XSEC objects for a new signature with no
<Reference> elements. In this case, the signature will be
made using Commented C14n canonicalisation, and a HMAC-SHA1
signature.
|
The XSECProvider class still "owns" the DSIGSignature object.
To delete the object, the original provider.release(sig) call
should be used. Never delete a DSIGSignature object directly.
|
|
|
|
|