# Smart Card Shell

- - Home
- - GPError
  - GPSystem
  - ByteString
  - ByteBuffer
  - TLV
  - TLVList
  - Card
  - Atr
  - Key
  - Crypto
  - Application
  - GPApplication
  - GPSecDomain
- - ASN1
  - CardFile
  - IsoSecureChannel
  - ApplFactory
  - GPXML
  - JsScript
  - CardSim
- - X509
  - CRL
  - KeyStore
  - Signed CMS
  - Enveloped CMS
  - CMS Generator
  - XMLSignature
  - SSS
  - OCSPQuery
  - LDAP
  - SOAP
  - URLConnection
- - PKCS11Provider
  - PKCS11Session
  - PKCS11Object
- - OutlineNode
  - Dialog
  - Task
- - Tools
  - Modules
- - 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

- XMLSignature() constructor
- addReference()
- sign()
- verify()
- saveAs()

## Constants

Type | Name | Description
--- | --- | ---
String | INCLUSIVE | The Canonical XML (without comments) canonicalization method algorithm URI
String | INCLUSIVE_WITH_COMMENTS | The Canonical XML with comments canonicalization method algorithm URI
String | EXCLUSIVE | The Exclusive Canonical XML (without comments) canonicalization method algorithm URI
String | EXCLUSIVE_WITH_COMMENTS | The Exclusive Canonical XML with comments canonicalization method algorithm URI
String | BASE64 | The Base64 transform algorithm URI
String | ENVELOPED | The Enveloped Signature transform algorithm URI
String | XPATH | The XPath transform algorithm URI
String | XPATH2 | The XPath Filter 2 transform algorithm URI
String | XSLT | The XSLT transform algorithm URI

## Constructor

### Prototype

XMLSignature(String filename)

### Description

Create object and initialize from document in referenced file.

### Arguments

Type | Name | Description
--- | --- | ---
`String` | filename | Name of file containing XML document, signed or unsigned.

### Exceptions

Name | Value | Description
--- | --- | ---
GPError | GPError.ARGUMENTS_MISSING | Too few arguments in call
GPError | GPError.INVALID_ARGUMENTS | Too many arguments in call
GPError | GPError.INVALID_TYPE | Type 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

Type | Name | Description
--- | --- | ---
`String` | uri | The URI pointing to the signed data
`Number` | digestMech | One of Crypto.SHA_1, Crypto.SHA_256, Crypto.SHA_512 or Crypto.MD5
`String[]` | transformations | List of transformations to apply for reference

### Return

`` |

### Exceptions

Name | Value | Description
--- | --- | ---
GPError | GPError.ARGUMENTS_MISSING | Too few arguments in call
GPError | GPError.INVALID_ARGUMENTS | Too many arguments in call
GPError | GPError.INVALID_TYPE | Type 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

Type | Name | Description
--- | --- | ---
`Crypto` | crypto | The crypto service to use
`String` | c14n | The canonicalization method to apply
`Key` | mech | The signature mechanism to use
`Key` | privateKey | The private key used for signing
`Key` | publicKey | The public key to be included in KeyInfo

### Return

`` |

### Exceptions

Name | Value | Description
--- | --- | ---
GPError | GPError.ARGUMENTS_MISSING | Too few arguments in call
GPError | GPError.INVALID_ARGUMENTS | Too many arguments in call
GPError | GPError.INVALID_TYPE | Type of argument is invalid for call
GPError | GPError.CRYPTO_FAILED | The 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

Type | Name | Description
--- | --- | ---
`Crypto` | crypto | The crypto service to use
`Key` | publicKey | The public key to be used for verification

### Return

`` |

### Exceptions

Name | Value | Description
--- | --- | ---
GPError | GPError.ARGUMENTS_MISSING | Too few arguments in call
GPError | GPError.INVALID_ARGUMENTS | Too many arguments in call
GPError | GPError.INVALID_TYPE | Type of argument is invalid for call
GPError | GPError.CRYPTO_FAILED | The 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

Name | Value | Description
--- | --- | ---
GPError | GPError.ARGUMENTS_MISSING | Too few arguments in call
GPError | GPError.INVALID_ARGUMENTS | Too many arguments in call
GPError | GPError.INVALID_TYPE | Type of argument is invalid for call

### Example

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

    ds.saveAs(fn);

© Copyright 2003 - 2024 CardContact Systems GmbH , Minden, Germany