public class Module
extends java.lang.Object
Module pkcs11Module = Module.getInstance("cryptoki.dll");
pkcs11Module.initialize(null);
// ... work with the module
pkcs11Module.finalize(null);
Instead of cryptoki.dll
, the application will use the name of the PKCS#11 module of
the installed crypto hardware. After the application initialized the module, it can get a list of
all available slots. A slot is an object that represents a physical or logical device that can
accept a cryptographic token; for instance, the card slot of a smart card reader. The application
can call
Slot[] slots = pkcs11Module.getSlotList(Module.SlotRequirement.ALL_SLOTS);
to get a list of all available slots or
Slot[] slotsWithToken = pkcs11Module.getSlotList(Module.SlotRequirement.TOKEN_PRESENT);
to get a list of all those slots in which there is a currently a token present.
To wait for the insertion of a token, the application can use the waitForSlotEvent
method. For example, the method call
Slot eventSlot = pkcs11Module.waitForSlotEvent(Module.WaitingBehavior.DONT_BLOCK, null);
will block until an event for any slot of this module occurred. Usually such an event is the
insertion of a token. However, the application should check if the event occurred in the slot of
interest and if there is really a token present in the slot.Modifier and Type | Class and Description |
---|---|
static interface |
Module.SlotRequirement
This interface defines the required properties for a slot.
|
static interface |
Module.WaitingBehavior
This interface defines the allowed constants for the wanted waiting behavior when calling
waitForSlotEvent.
|
Modifier and Type | Field and Description |
---|---|
protected PKCS11 |
pkcs11Module_
Interface to the underlying PKCS#11 module.
|
Modifier | Constructor and Description |
---|---|
protected |
Module(PKCS11 pkcs11Module)
Create a new module that uses the given PKCS11 interface to interact with the token.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object otherObject)
Compares the pkcs11Module_ this object with the other object.
|
void |
finalize()
This finalize method tries to finalize the module by calling
finalize() of the
Java object of the PKCS11 module. |
void |
finalize(java.lang.Object args)
Finalizes this module.
|
Info |
getInfo()
Gets information about the module; i.e.
|
static Module |
getInstance(java.lang.String pkcs11ModuleName)
Get an instance of this class by giving the name of the PKCS#11 module; e.g.
|
static Module |
getInstance(java.lang.String pkcs11ModuleName,
boolean wrapperDebugVersion)
Get an instance of this class by giving the name of the PKCS#11 module; e.g.
|
static Module |
getInstance(java.lang.String pkcs11ModuleName,
java.lang.String pkcs11WrapperPath)
Get an instance of this class by giving the name of the PKCS#11 module, e.g.
|
PKCS11 |
getPKCS11Module()
Gets the PKCS#11 module of the wrapper package behind this object.
|
Slot[] |
getSlotList(boolean tokenPresent)
Gets a list of slots that can accept tokens that are compatible with this module; e.g.
|
int |
hashCode()
The overriding of this method should ensure that the objects of this class work correctly in a
hashtable.
|
void |
initialize(InitializeArgs initArgs)
Initializes the module.
|
java.lang.String |
toString()
Returns the string representation of this object.
|
Slot |
waitForSlotEvent(boolean dontBlock,
java.lang.Object reserved)
Waits for an slot event.
|
protected PKCS11 pkcs11Module_
protected Module(PKCS11 pkcs11Module)
pkcs11Module
- The interface to interact with the token.public static Module getInstance(java.lang.String pkcs11ModuleName) throws java.io.IOException
pkcs11ModuleName
- The name of the module; e.g. "slbck.dll".java.io.IOException
- If connecting to the named module fails.public static Module getInstance(java.lang.String pkcs11ModuleName, boolean wrapperDebugVersion) throws java.io.IOException
pkcs11ModuleName
- The name of the module; e.g. "slbck.dll".wrapperDebugVersion
- true, if the PKCS#11 wrapper library's debug version shall be loadedjava.io.IOException
- If connecting to the named module fails.public static Module getInstance(java.lang.String pkcs11ModuleName, java.lang.String pkcs11WrapperPath) throws java.io.IOException
pkcs11ModuleName
- The name of the module; e.g. "slbck.dll".pkcs11WrapperPath
- The absolute path to the PKCS#11-wrapper native library.java.io.IOException
- If connecting to the named module fails.public Info getInfo() throws TokenException
TokenException
- If getting the information fails.public void initialize(InitializeArgs initArgs) throws TokenException
initArgs
- The initialization arguments for the module as defined in PKCS#11. May be null.TokenException
- If initialization fails.public void finalize(java.lang.Object args) throws TokenException
finalize
method, which is the
reserved Java method called by the garbage collector. This method calls the
C_Finalize(Object)
method of the underlying PKCS11 module.args
- Must be null in version 2.x of PKCS#11.TokenException
- If finalization fails.public Slot[] getSlotList(boolean tokenPresent) throws TokenException
tokenPresent
- Can be SlotRequirement.ALL_SLOTS or SlotRequirement.TOKEN_PRESENT.TokenException
- If .public Slot waitForSlotEvent(boolean dontBlock, java.lang.Object reserved) throws TokenException
dontBlock
- Can be WaitingBehavior.BLOCK or WaitingBehavior.DONT_BLOCK.reserved
- Should be null for this version.TokenException
- If the method was called with WaitingBehavior.DONT_BLOCK but there was no event
available, or if an error occured.public PKCS11 getPKCS11Module()
public java.lang.String toString()
toString
in class java.lang.Object
public void finalize() throws java.lang.Throwable
finalize()
of the
Java object of the PKCS11 module. Note that this method does not call the
finalize(Object)
(C_Finalize(Objet)
) method of the PKCS11 module!
This method is the reserved Java method called by the garbage collector. Don't get confused by
the same name.finalize
in class java.lang.Object
java.lang.Throwable
- If finalization fails.finalize(Object)
public boolean equals(java.lang.Object otherObject)
equals
in class java.lang.Object
otherObject
- The other Module object.public int hashCode()
hashCode
in class java.lang.Object
IAIK JavaSecurity Website http://jce.iaik.tugraz.at/
IAIK at Graz University of Technology, Austria, Europe
Copyright 2001-2023 IAIK, Graz University of Technology, Inffeldgasse 16a, 8010 Graz, Austria. All Rights Reserved. version 1.6.9