Hi,
can anyone tell me what's wrong with this piece of code?
The access condition for the create file command in the root file is
0x04, which means "you must know a cryptographic key". I'm using the 3k
Multiflex card from Schlumberger which comes with the book "Smart Card
Developer's Kit".
********************************************************
// command to ask card for a challenge
byte[] chall = { (byte) 0xC0, (byte) 0x84, (byte) 0x00, (byte) 0x00,
(byte) 0x08};
// first bytes for creating a file
byte[] CREATE_FILE = { (byte) 0xF0, (byte) 0xE0, (byte) 0x00};
String sfilename = "EF_TEST_CHD";
byte[] bfilename = sfilename.getBytes();
// 0x05 is number of records, 0x11 is sum of length of following 2
fields
byte[] temp = { (byte) 0x05, (byte) 0x11 };
try {
CommandAPDU capdu = new CommandAPDU(5);
capdu.append(chall);
ResponseAPDU rapdu = terminal.sendAPDU(currentSlot,capdu);
byte sw1 = rapdu.sw1();
byte sw2 = rapdu.sw2();
byte[] data = rapdu.data();
if ((sw1 == (byte) 0x90) && (sw2 == (byte) 0x00)) {
System.out.print("Encrypting challenge...\n");
byte[] crypt = new byte[8];
// the DES_KEY is the key that is provided with the book
DESKey deskey = new DESKey(DES_KEY);
deskey.encrypt(data,0,crypt,0);
System.out.print("Encrypted data: " + HexString.hexify(crypt) +
"\n");
CommandAPDU capdufile = new CommandAPDU(30);
capdufile.append(CREATE_FILE);
capdufile.append(temp);
capdufile.append(bfilename);
int i;
byte[] auth = new byte[6];
// the create file command needs the first 6 bytes of the
encryption as a last parameter
for (i=0;i<6;i++) {
auth[i] = crypt[i];
}
capdufile.append(auth);
System.out.print("APDU: " +
HexString.hexify(capdufile.getBytes()) + "\n");
ResponseAPDU rapdufile =
terminal.sendAPDU(currentSlot,capdufile);
byte swfile1 = rapdufile.sw1();
byte swfile2 = rapdufile.sw2();
byte[] datafile = rapdufile.data();
System.out.print("SW1: " + HexString.hexify(swfile1) +
"\n");
System.out.print("SW2: " + HexString.hexify(swfile2) + "\n");
}
}
catch (Exception e) {
}
***********************************************************************************
Thanks,
--
Eelco Daams
Internet Developer
BuyWays, de bouwers van www.surfze.nl
______________________________________________________
BuyWays Internet Strategie & Technologie
Damsterdiep 31a/b
9711 SG GRONINGEN
tel. 050-3118123
fax 050-3118124
gsm 06-10090866
http://www.buyways.nl
_______________________________________________________
Op al onze diensten zijn onze algemene voorwaarden
voor dienstverlening van toepassing, zoals gedeponeerd
bij de Kamer van Koophandel te Groningen, onder
nummer 3057.
---
> Visit the OpenCard web site at http://www.opencard.org/ for more
> information on OpenCard---binaries, source code, documents.
> This list is being archived at http://www.opencard.org/archive/opencard/
! To unsubscribe from the [EMAIL PROTECTED] mailing list send an email
! to
! [EMAIL PROTECTED]
! containing the word
! unsubscribe
! in the body.