private void signDecryptHelper(final RSACryptoSystem cryptoSystem,
final CryptoTokenPrivateKeyData privateKeyData, final byte[] input,
final int inputOffset, final byte[] output, final int outputOffset,
final String accessReason, final int operation)
throws CryptoTokenException, CryptoUnsupportedOperationException {
SmartCardSession smartCardSession = null;
try {
if (privateKeyData instanceof MyCryptoTokenData) {
final SmartCardID smartCardID =
((MyCryptoTokenData) privateKeyData).getSmartCardID();
smartCardSession =
SmartCardFactory.getSmartCardSession(smartCardID);
if (smartCardSession instanceof MyCryptoSmartCardSession) {
final MyCryptoSmartCardSession mySmartCardSession =
(MyCryptoSmartCardSession) smartCardSession;
// We must provide the user authentication since we returned
// true from providesUserAuthentication()
// Also, the smart card PIN is required for private key
// access.
mySmartCardSession.loginPrompt(accessReason, operation);
mySmartCardSession.signDecrypt(cryptoSystem,
(MyCryptoTokenData) privateKeyData, input,
inputOffset, output, outputOffset);
return;
}
}
throw new RuntimeException();
} catch (final SmartCardSessionClosedException e) {
throw new CryptoTokenCancelException(e.toString());
} catch (final SmartCardCancelException e) {
throw new CryptoTokenCancelException(e.toString());
} catch (final SmartCardRemovedException e) {
throw new CryptoTokenCancelException(e.toString());
} catch (final SmartCardException e) {
throw new CryptoTokenException(e.toString());
} finally {
if (smartCardSession != null) {
smartCardSession.close();
}
}
}