23
3: Code samples
/**
* Send some data to the smart card for signing or decryption.
*/
/*package*/ void signDecrypt( RSACryptoSystem cryptoSystem,
MyCryptoTokenData privateKeyData,byte[] input, int inputOffset,
byte[] output, int outputOffset ) throws SmartCardException
{
// Check for nulls
if ( cryptoSystem == null || privateKeyData == null || input == null || output ==
null) {
throw new IllegalArgumentException();
}
// Validate the input parameters
int modulusLength = cryptoSystem.getModulusLength();
if ( ( input.length < input modulusLength ) || ( output.length <
output modulusLength ) ) {
throw new IllegalArgumentException();
}
// Construct the response Application Protocol Data Unit
ResponseAPDU response = new ResponseAPDU();
// Construct the command and set its information
// Create a CommandAPDU which your smart card will understand
CommandAPDU signAPDU = new CommandAPDU( (byte)0x80, (byte)0x56, (byte)0x00,
(byte)0x00, modulusLength );
signAPDU.setLcData( input, inputOffset, input.length - inputOffset );
// Send the command to the smart card
sendAPDU( signAPDU, response );
// Validate the status words of the response
// Check for response codes specific to your smart card
if ( response.checkStatusWords( (byte)0x90, (byte)0x00 ) ) {
byte [] responseData = response.getData();
System.arraycopy( responseData, 0, output, outputOffset, responseData.length );
}
else {
throw new SmartCardException( “Invalid response code, sw1=” +
Integer.toHexString( response.getSW1() & 0xff ) + “ sw2=” + Integer.toHexString(
response.getSW2() & 0xff ) );
}
}
}
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...