Skip to content

CryptoToken

Endi S. Dewata edited this page Jul 29, 2022 · 1 revision

Getting All Tokens

CryptoManager manager = CryptoManager.getInstance();
Enumeration<CryptoToken> tokens = manager.getAllTokens();

whlie (tokens.hasMoreElements()) {
    CryptoToken token = tokens.nextElement();
    ...
}

Getting a Token

CryptoManager manager = CryptoManager.getInstance();

CryptoToken token;

if (...) {
    token = manager.getInternalKeyStorageToken();
} else {
    token = manager.getTokenByName(tokenName);
}

manager.setThreadToken(token);

Authentication

To authenticate with PasswordCallback:

public interface PasswordCallback {
    public Password getPasswordFirstAttempt(PasswordCallbackInfo info) throws GiveUpException;
    public Password getPasswordAgain(PasswordCallbackInfo info) throws GiveUpException;
}
PasswordCallback pc = ...;
manager.setPasswordCallback(pc);

To authenticate with password:

Password password = new Password(chars);
token.login(password);
password.clear();