public class Token extends Object
long[] supportedMechanisms = token.getMechanismList();
// check, if the token supports the required mechanism
if (!contains(supportedMechanisms, CKM_RSA_PKCS)) {
System.out.print("This token does not support the RSA PKCS mechanism!");
System.out.flush();
throw new TokenException("RSA not supported!");
} else {
MechanismInfo rsaMechanismInfo = token.getMechanismInfo(CKM_RSA_PKCS);
// check, if the mechanism supports the required operation
if (!rsaMechanismInfo.isDecrypt()) {
System.out.print(
"This token does not support RSA decryption according to PKCS!");
System.out.flush();
throw new TokenException("RSA signing not supported!");
}
}
Being sure that the token supports the required mechanism, the application
can open a session. For example, it may call
Session session = token.openSession(readWrite);
to open a read-only session for readWrite = false, or a read-write session if
readWrite = true.| Modifier | Constructor and Description |
|---|---|
protected |
Token(Slot slot)
The constructor that takes a reference to the module and the slot ID.
|
| Modifier and Type | Method and Description |
|---|---|
MechanismInfo |
getMechanismInfo(long mechanism)
Get more information about one supported mechanism.
|
long[] |
getMechanismList()
Get the list of mechanisms that this token supports.
|
Slot |
getSlot()
Get the slot that created this Token object.
|
long |
getTokenID()
Get the ID of this token.
|
TokenInfo |
getTokenInfo()
Get information about this token.
|
boolean |
isUseUtf8Encoding() |
Session |
openSession(boolean rwSession)
Open a new session to perform operations on this token.
|
Session |
openSession(boolean rwSession,
Object application)
Open a new session to perform operations on this token.
|
String |
toString()
Returns the string representation of this object.
|
protected Token(Slot slot)
slot - The reference to the slot.public Slot getSlot()
public boolean isUseUtf8Encoding()
public long getTokenID()
public TokenInfo getTokenInfo() throws PKCS11Exception
PKCS11Exception - If reading the information fails.public long[] getMechanismList()
public MechanismInfo getMechanismInfo(long mechanism)
mechanism - A mechanism that is supported by this token.public Session openSession(boolean rwSession) throws PKCS11Exception
rwSession - Must be either SessionReadWriteBehavior.RO_SESSION for read-only
sessions or SessionReadWriteBehavior.RW_SESSION for read-write
sessions.PKCS11Exception - If the session could not be opened.public Session openSession(boolean rwSession, Object application) throws PKCS11Exception
rwSession - Must be either SessionReadWriteBehavior.RO_SESSION for read-only
sessions or SessionReadWriteBehavior.RW_SESSION for read-write
sessions.application - PKCS11Object to be supplied upon notify callback. May be null.
(Not implemented yet!).PKCS11Exception - If the session could not be opened.Copyright © 2023. All rights reserved.