# 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

# PKCS11Provider - Reference Documentation

Class implementing support for cryptographic token with PKCS#11 interface

## Index of Methods

- PKCS11Provider() constructor
- getSlots()
- initToken()
- getKeyStore()
- cleanup()

## Properties

Type | Name | Description
--- | --- | ---
String | providerName | Name under which this provider is registered

## Constructor

### Prototype

PKCS11Provider(String providerName)

### Description

Load and access provider module.

### Arguments

Type | Name | Description
--- | --- | ---
`String` | providerName | Name and path of .DLL or shared object

### 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 p = new PKCS11Provider("c:/programme/smart card bundle/opensc-pkcs11.dll");
    var p = new PKCS11Provider("C:/usr/local/lsm/bin/lsmpkcs11.dll");
    // var p = new PKCS11Provider("C:/programme/opensc/bin/pkcs11-spy.dll");

## getSlots()

### Prototype

Array getSlots()

### Description

Return an array of native PKCS11Slot objects.

The objects in the array are of type org.opensc.pkcs11.wrap.PKCS11Slot.

### Return

`Array` | Array of native PKCS11Slot objects

### 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 slots = p.getSlots();
    var slot = 0;

    for (var i = 0; i < slots.length; i++) {
    	var s = slots[i];
    	print("Slot #" + s.getId());
    	print(" Description       : " + s.getDescription());
    	print(" Manufacturer      : " + s.getManufacturer());
    	print(" Hardware Version  : " + s.getHardwareVersion());
    	print(" Firmware Version  : " + s.getFirmwareVersion());
    	print(" isTokenPresent    : " + s.isTokenPresent());
    	print(" isHardwareDevice  : " + s.isHardwareDevice());
    	print(" isRemovableDevice : " + s.isRemovableDevice());

    	if (s.isTokenPresent()) {
    		var label = s.getTokenLabel();

    		if (label == "SBOXTEST1") {
    			print("Found " + label);
    			slot = s.getId();
    		}

    		print("  Token :");
    		print("  Label                     : " + label);
    		print("  Manufacturer              : " + s.getTokenManufacturer());
    		print("  Model                     : " + s.getTokenModel());
    		print("  Serial Number             : " + s.getTokenSerialNumber());
    		print("  Max PIN Length            : " + s.getTokenMaxPinLen());
    		print("  Min PIN Length            : " + s.getTokenMinPinLen());
    		print("  hasTokenProtectedAuthPath : " + s.hasTokenProtectedAuthPath());

    		var mechs = s.getMechanisms();
    		for (var j = 0; j < mechs.length; j++) {
    			print("   Mechanisms #" + j);
    			var m = mechs[j];
    			print("   Type         : " + m.getType() + " (" + m.getTypeName() + ")");
    			print("   Min Key Size : " + m.getMinKeySize());
    			print("   Max Key Size : " + m.getMaxKeySize());
    			print("   Flags        : " + m.getFlags());
    		}
    	}
    }

## initToken()

### Prototype

initToken(Number slotId, String soPIN, String label)

### Description

Initialize token in referenced slot and set the Security Officer (SO) PIN and label.

If the token is already initialized, then the SO PIN must match the tokens SO PIN.

### Arguments

Type | Name | Description
--- | --- | ---
`Number` | slotId | The slot id of the slot to initialize
`String` | soPIN | The Security Officers PIN
`String` | label | The tokens label

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

    p.initToken(slot, "abcdefgh", "SBOXTEST1");

## getKeyStore()

### Prototype

KeyStore getKeyStore(Number slot)

KeyStore getKeyStore(Number slot, String userPIN)

### Description

Obtain the key store for a token in the selected slot.

The key store can be used to create key objects that represent keys in the token.

### Arguments

Type | Name | Description
--- | --- | ---
`Number` | slot | Slot number
`String` | userPIN | User PIN for token

### Return

`KeyStore` | KeyStore object

### 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 ks = p.getKeyStore(slot, "12345678");

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

    var k = new Key();
    k.setType(Key.PRIVATE);
    k.setID(aliases[0]);

    ks.getKeyFromKeyStore(k);

    var c = new Crypto(p.providerName);

    var message = new ByteString("Hello World", ASCII);
    var signature = c.sign(k, Crypto.RSA, message);

    print(signature);

## cleanup()

### Prototype

cleanup()

### Description

Cleanup provider and release used system resources.

This will be done automatically when the Java Runtime terminates.

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

    p.cleanup();

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