public class Token extends Object
List supportedMechanisms = Arrays.asList(token.getMechanismList());
// check, if the token supports the required mechanism
if (!supportedMechanisms.contains(Mechanism.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(Mechanism.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(Token.SessionType.SERIAL_SESSION,
Token.SessionReadWriteBehavior.RO_SESSION, null, null);
to open a simple read-only session.Mechanism,
MechanismInfo,
Session,
TokenInfo| Modifier and Type | Class and Description |
|---|---|
static interface |
Token.SessionReadWriteBehavior
This interface defines constants that specify the read/write behavior of
a session.
|
static interface |
Token.SessionType
This interface defines constants for the type of session that should
be opened upon a call to openSession.
|
| 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 |
|---|---|
boolean |
equals(Object otherObject)
Compares the slot of this object with the other object.
|
MechanismInfo |
getMechanismInfo(Mechanism mechanism)
Get more information about one supported mechanism.
|
Mechanism[] |
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.
|
int |
hashCode()
The overriding of this method should ensure that the objects of this
class work correctly in a hashtable.
|
boolean |
isUseUtf8Encoding() |
Session |
openSession(boolean serialSession,
boolean rwSession,
Object application,
Notify notify)
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 boolean equals(Object otherObject)
public Slot getSlot()
public boolean isUseUtf8Encoding()
public long getTokenID()
public TokenInfo getTokenInfo() throws TokenException
TokenException - If reading the information fails.public Mechanism[] getMechanismList() throws TokenException
TokenException - If reading the list of supported mechanisms fails.public MechanismInfo getMechanismInfo(Mechanism mechanism) throws TokenException
mechanism - A mechanism that is supported by this token.TokenException - If reading the information fails, or if the mechanism is not
supported by this token.public int hashCode()
public Session openSession(boolean serialSession, boolean rwSession, Object application, Notify notify) throws TokenException
serialSession - Must be SessionType.SERIAL_SESSION. (For the sake of
completeness)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!).notify - For notifications via callback. may be null.
(Not implemented yet!)TokenException - If the session could not be opened.Copyright © 2018. All rights reserved.