# Scripting Server

- - Home
- - HttpRequest
  - HttpResponse
- - 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
  - OCSPQuery
  - LDAP
  - SOAP
  - URLConnection
- - PKCS11Provider
  - PKCS11Session
  - PKCS11Object
- - OpenSCDP

# KeyStore - Reference Documentation

Class implementing access to Java key stores from JavaScript

## Index of Methods

- KeyStore() constructor
- getAliases()
- getKey()
- getCertificate()
- setKey()
- setCertificate()
- store()

## Properties

Type | Name | Description
--- | --- | ---
java.security.KeyStore | native | The native Java keystore object

## Constructor

### Prototype

KeyStore(String provider, String type, String filename, String password)

KeyStore(String provider, String type, String filename)

KeyStore(String provider, String type)

KeyStore(String provider)

### Description

Create and load key store

### Arguments

Type | Name | Description
--- | --- | ---
`String` | provider | Provider to use for key store access
`String` | type | Key store type. Default is "jks".
`String` | filename | Name of file containing keys. Default is empty.
`String` | password | Password used to access key store. Default is no password.

### 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 | Accessing key store failed

### Example

    var ks = new KeyStore("BC", "BKS", "sample.bks", "1234");
    // var ks = new KeyStore("SUN", "JKS");
    // var ks = new KeyStore("SunJCE", "JCEKS");

## getAliases()

### Prototype

String[] getAliases()

### Description

Return list of aliases defined in key store.

### Return

`String[]` | Array containing alias names from key store

### 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 | Accessing key failed

### Example

    var aliases = ks.getAliases();
    for (var i = 0; i < aliases.length; i++) {
    	print(aliases[i]);
    }

## getKey()

### Prototype

getKey(Key key)

getKey(Key key, String password)

### Description

Link key object with key instance in key store using the key id.

### Arguments

Type | Name | Description
--- | --- | ---
`Key` | key | Key object
`String` | password | Password to access key instance

### 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 | Accessing key failed

### Example

    var k = new Key();
    k.setType(Key.PRIVATE);
    k.setID("openscdp");

    ks.getKey(k, "1234");

## getCertificate()

### Prototype

getCertificate(String alias)

### Description

Get named certificate from keystore.

### Arguments

Type | Name | Description
--- | --- | ---
`String` | alias | Alias name of certificate

### 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 cert = ks.getCertificate("openscdp");
    assert(cert.getSubjectDNString() == "E=support@openscdp.org,C=DE,L=Minden," +
                                        "O=CardContact,CN=OpenSCDP");

## setKey()

### Prototype

setKey(Key key)

setKey(Key key, String password)

setKey(Key key, String password, X590[] certificates)

### Description

Store key in key store, encrypted with optional password. Private keys may only be stored with associated certificate chain.

### Arguments

Type | Name | Description
--- | --- | ---
`Key` | key | Key object
`String` | password | Password to access key instance
`X509[]` | certificates | Chain of certificates

### 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 | Accessing key failed

### Example

    k.setID("test");

    ks.setKey(k, "1234", [cert]);

## setCertificate()

### Prototype

setCertificate(String alias, X509 certificate)

### Description

Store certificate in key store.

### Arguments

Type | Name | Description
--- | --- | ---
`X509` | certificate | Certificate

### 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 | Accessing key failed

### Example

    ks.setCertificate("test", cert);

## store()

### Prototype

store()

store(String filename)

setKey(String filename, String password)

### Description

Save keystore to persistent storage

### Arguments

Type | Name | Description
--- | --- | ---
`String` | filename | File name for storing the key store
`String` | password | Password to access key instance

### 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 | Accessing key failed

### Example

    ks.store("newstore.bks", "1234");

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