Blackberry JAVA DEVELOPMENT ENVIRONMENT - - CRYPTOGRAPHIC SMART CARD DRIVER - DEVELOPMENT GUIDE Manual page 31

Cryptographic smart card driver
Table of Contents

Advertisement

{
signDecryptHelper( cryptoSystem, privateKeyData, input, inputOffset, output,
outputOffset, SIGN_DESC, SmartCardSession.SIGN_OPERATION );
}
/**
* Help signing and decryption operations.
* This helper method assists data signing and decryption because
* the operations are very similar.
*/
private void signDecryptHelper( RSACryptoSystem cryptoSystem,
CryptoTokenPrivateKeyData privateKeyData, byte[] input, int inputOffset,
byte[] output, int outputOffset,String accessReason,int operation )
throws CryptoTokenException, CryptoUnsupportedOperationException
{
SmartCardSession smartCardSession = null;
try {
if( privateKeyData instanceof MyCryptoTokenData ) {
SmartCardID smartCardID = ((MyCryptoTokenData) privateKeyData
).getSmartCardID();
smartCardSession = SmartCardFactory.getSmartCardSession( smartCardID );
if ( smartCardSession instanceof MyCryptoSmartCardSession ) {
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 ( SmartCardSessionClosedException e ) {
throw new CryptoTokenCancelException( e.toString() );
} catch ( SmartCardCancelException e ) {
throw new CryptoTokenCancelException( e.toString() );
} catch( SmartCardRemovedException e ) {
throw new CryptoTokenCancelException( e.toString() );
} catch ( SmartCardException e ) {
throw new CryptoTokenException( e.toString() );
} finally {
if ( smartCardSession != null ) {
smartCardSession.close();
}
3: Code samples
27

Advertisement

Table of Contents
loading

This manual is also suitable for:

Java development environment 4.6.0

Table of Contents