27
3: Code samples
{
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();
}
Summary of Contents for JAVA DEVELOPMENT ENVIRONMENT - - CRYPTOGRAPHIC SMART CARD DRIVER - DEVELOPMENT GUIDE
Page 4: ......
Page 6: ......
Page 14: ...10 Cryptographic Smart Card Driver Development Guide...
Page 17: ...13 2 Testing a cryptographic smart card driver...
Page 18: ...14 Cryptographic Smart Card Driver Development Guide...
Page 34: ...30 Cryptographic Smart Card Driver Development Guide...
Page 35: ......
Page 36: ...2007 Research In Motion Limited Published in Canada...