public class Token
extends java.lang.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 and Type | Field and Description |
---|---|
protected Slot |
slot_
The reference to the slot.
|
protected boolean |
useUtf8Encoding_
True, if UTF8 encoding is used as character encoding for character array attributes and PINs.
|
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 |
---|---|
void |
closeAllSessions()
Close all open sessions of this token.
|
boolean |
equals(java.lang.Object otherObject)
Compares the slot_ of this object with the other object.
|
MechanismInfo |
getMechanismInfo(Mechanism mechanism)
Get mor 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.
|
void |
initToken(char[] pin,
java.lang.String label)
Initialize the token.
|
boolean |
isLoginRequired() |
Session |
openSession(boolean serialSession,
boolean rwSession,
java.lang.Object application,
Notify notify)
Open a new session to perfom operations on this token.
|
java.lang.String |
toString()
Returns the string representation of this object.
|
protected Slot slot_
protected boolean useUtf8Encoding_
protected Token(Slot slot)
slot
- The reference to the slot.public boolean equals(java.lang.Object otherObject)
equals
in class java.lang.Object
otherObject
- The other Token object.public Slot getSlot()
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 mechansisms 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 mechansim is not supported by this
token.public int hashCode()
hashCode
in class java.lang.Object
public void initToken(char[] pin, java.lang.String label) throws TokenException
pin
- If the token is not initialized yet, this PIN becomes the security officer (admin)
PIN. If the token is already initialized, this PIN must be the correct security
officer PIN of this token. Otherwise the operation will fail. If the token slot has
build-in means to verify the user (e.g. a PIN-pad on the card reader), this parameter
can be null.label
- The label to give to the token. If this string is longer than 32 characters, it will
be cut off at the end to be exactly 32 characters in length. If it is shorter than 32
characters, the label is filled up with the blank character (' ') to be exactly 32
characters in length.TokenException
- If the initialization fails.public Session openSession(boolean serialSession, boolean rwSession, java.lang.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
- Object 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.public void closeAllSessions() throws TokenException
TokenException
- If closing all session fails.public boolean isLoginRequired() throws TokenException
TokenException
public java.lang.String toString()
toString
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