SSE4E

Home

GPError
GPSystem
ByteString
ByteBuffer
TLV
TLVList
Card
Atr
Key
Crypto
Application GPApplication GPSecDomain

ASN1
CardFile
IsoSecureChannel
ApplFactory
GPXML
JsScript
CardSim

X509
CRL
KeyStore
CMSSignedData
CMSGenerator
XMLSignature
OCSPQuery
LDAP
SOAP
URLConnection

PKCS11Provider
PKCS11Session
PKCS11Object

OutlineNode

OpenSCDP

XMLSignature - Reference Documentation

Class implementing support for XML Digital Signatures

This class provides for the ability to create and verify XML Digital Signatures.

Index of Methods

Constants

TypeNameDescription
StringINCLUSIVEThe Canonical XML (without comments) canonicalization method algorithm URI
StringINCLUSIVE_WITH_COMMENTSThe Canonical XML with comments canonicalization method algorithm URI
StringEXCLUSIVEThe Exclusive Canonical XML (without comments) canonicalization method algorithm URI
StringEXCLUSIVE_WITH_COMMENTSThe Exclusive Canonical XML with comments canonicalization method algorithm URI
StringBASE64The Base64 transform algorithm URI
StringENVELOPEDThe Enveloped Signature transform algorithm URI
StringXPATHThe XPath transform algorithm URI
StringXPATH2The XPath Filter 2 transform algorithm URI
StringXSLTThe XSLT transform algorithm URI

Constructor

Prototype

XMLSignature(String filename)

Description

Create object and initialize from document in referenced file.

Arguments

TypeNameDescription
StringfilenameName of file containing XML document, signed or unsigned.

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call

Example


var ds = new XMLSignature("xmlsig1.xml");

addReference()

Prototype

void addReference(String uri, Number digestMech)

void addReference(String uri, Number digestMech, String[] transformations)

Description

Add a reference to the SignedInfo

Arguments

TypeNameDescription
StringuriThe URI pointing to the signed data
NumberdigestMechOne of Crypto.SHA_1, Crypto.SHA_256, Crypto.SHA_512 or Crypto.MD5
String[]transformationsList of transformations to apply for reference

Return

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call

Example


ds.addReference("", Crypto.SHA_256, [XMLSignature.ENVELOPED]);
ds.addReference("./xmlsig1.xml", Crypto.SHA_256);

sign()

Prototype

void sign(Crypto crypto, String c14n, Number mech, Key privateKey, Key publicKey)

Description

Create signature using the private key and signature mechanism.

The data to be signed is canonicalized using the selected method.

The public key is stored in the KeyInfo section.

Arguments

TypeNameDescription
CryptocryptoThe crypto service to use
Stringc14nThe canonicalization method to apply
KeymechThe signature mechanism to use
KeyprivateKeyThe private key used for signing
KeypublicKeyThe public key to be included in KeyInfo

Return

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call
GPErrorGPError.CRYPTO_FAILEDThe cryptographic signing operation failed

Example


// Create empty public key object and set size
var pubKey = new Key();
pubKey.setType(Key.PUBLIC);
pubKey.setSize(1024);

// Create empty private key object and set size
var priKey = new Key();
priKey.setType(Key.PRIVATE);

var crypto = new Crypto();

// Generate key pair
crypto.generateKeyPair(Crypto.RSA, pubKey, priKey);

ds.sign(crypto, XMLSignature.EXCLUSIVE, Crypto.RSA_SHA256, priKey, pubKey);

verify()

Prototype

boolean verify(Crypto crypto, Key publicKey)

Description

Verify XML signature using the public key provided.

Arguments

TypeNameDescription
CryptocryptoThe crypto service to use
KeypublicKeyThe public key to be used for verification

Return

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call
GPErrorGPError.CRYPTO_FAILEDThe cryptographic verifying operation failed

Example


assert(ds.verify(crypto, pubKey));

saveAs()

Prototype

void saveAs(String filename)

Description

Save XML Digital Signature to file.

Return

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call

Example


var fn = GPSystem.mapFilename("xmlsig2.xml", GPSystem.CWD);

ds.saveAs(fn);