KeyStore - Reference Documentation

Class implementing access to Java key stores from JavaScript

Index of Methods

Properties

TypeNameDescription
java.security.KeyStorenativeThe 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

TypeNameDescription
StringproviderProvider to use for key store access
StringtypeKey store type. Default is "jks".
StringfilenameName of file containing keys. Default is empty.
StringpasswordPassword used to access key store. Default is no password.

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_FAILEDAccessing key store failed

Example


var ks = new KeyStore("BC", "BKS", "sample.bks", "1234");

getAliases()

Prototype

String[] getAliases()

Description

Return list of aliases defined in key store.

Return

String[]Array containing alias names from key store

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_FAILEDAccessing 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

TypeNameDescription
KeykeyKey object
StringpasswordPassword to access key instance

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_FAILEDAccessing 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

TypeNameDescription
StringaliasAlias name of certificate

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 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

TypeNameDescription
KeykeyKey object
StringpasswordPassword to access key instance
X509[]certificatesChain of certificates

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_FAILEDAccessing key failed

Example


k.setID("test");

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

store()

Prototype

store()

store(String filename)

setKey(String filename, String password)

Description

Save keystore to persistent storage

Arguments

TypeNameDescription
StringfilenameFile name for storing the key store
StringpasswordPassword to access key instance

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_FAILEDAccessing key failed

Example


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