public class PKCS11Module
extends java.lang.Object
Objects of this class represent a PKCS#11 module. The application should create an instance by calling getInstance and passing the name of the PKCS#11 module of the desired token; e.g. "slbck.dll". The application must give the full path of the PKCS#11 module unless the module is in the system's search path or in the path of the java.library.path system property.
According to the specification, the application must call the initialize method before calling any other method of the module. This class contains slot and token management functions as defined by the PKCS#11 standard. All applications using this library will contain the following code.
PKCS11Module pkcs11Module = PKCS11Module.getInstance("cryptoki.dll");
pkcs11Module.initialize();
// ... 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(false);
to get a list of all available slots or
Slot[] slotsWithToken = pkcs11Module.getSlotList(true);
to get a list of all those slots in which there is a currently a token
present.
| Modifier | Constructor and Description |
|---|---|
protected |
PKCS11Module(java.lang.String pkcs11ModulePath)
Create a new module that uses the given PKCS11 interface to interact with
the token.
|
| Modifier and Type | Method and Description |
|---|---|
void |
finalize(java.lang.Object args)
Caution:
Unlike the original PKCS#11 wrapper, we only call initialize() once per
native .so/.dll.
|
ModuleInfo |
getInfo()
Gets information about the module; i.e.
|
static PKCS11Module |
getInstance(java.lang.String pkcs11ModulePath)
Get an instance of this class by giving the name of the PKCS#11 module; e.g.
|
sun.security.pkcs11.wrapper.PKCS11 |
getPKCS11()
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.
|
void |
initialize()
Initializes the module.
|
java.lang.String |
toString()
Returns the string representation of this object.
|
protected PKCS11Module(java.lang.String pkcs11ModulePath)
pkcs11ModulePath - The interface to interact with the token.public static PKCS11Module getInstance(java.lang.String pkcs11ModulePath) throws java.io.IOException
pkcs11ModulePath - The path of the module; e.g. "/path/to/slbck.dll".java.io.IOException - If connecting to the named module fails.public ModuleInfo getInfo() throws PKCS11Exception
PKCS11Exception - If getting the information fails.public void initialize()
throws TokenException
PKCS11Exception - If initialization fails.TokenExceptionpublic Slot[] getSlotList(boolean tokenPresent) throws PKCS11Exception
tokenPresent - Whether only slots with present token are returned.PKCS11Exception - If error occurred.public sun.security.pkcs11.wrapper.PKCS11 getPKCS11()
public java.lang.String toString()
toString in class java.lang.Objectpublic void finalize(java.lang.Object args)
throws PKCS11Exception
Finalizes this module. The application should call this method when it
finished using the module.
Note that this method is different from the finalize method,
which is the reserved Java method called by the garbage collector.
This method calls the C_Finalize(PKCS11Object) method of the
underlying PKCS11 module.
args - Must be null in version 2.x of PKCS#11.PKCS11Exception - If finalization fails.Copyright © 2023. All rights reserved.