Hi,
You didn't give information about the GemXpresso RAD version, but i'm sure
it's an "IS" version.
The GSE Simulator is correct. The "IS" version is applying restrictions on
DES keys
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!! FOR EXPORT & DEVELOPMENT ONLY !!!!!.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
If you want non limited cards you have to make a request for them...
On IS versions, DES & 3DES is standard, but key are limited with the
following process.
For each key bytes
- if the_byte % 2 == 0 -> the_byte = 0xCA
- if the_byte % 2 == 1 -> the_byte = 0x2D
In your case (with full cards or full Simulator)
- key : 0 0 0 0 0 0 0 0
- data : 0 0 0 0 0 0 0 0
- result: 8C A6 4D E9 C1 B1 23 A7
With limitation (with "IS" cards or "IS" Simulator) your key is changed to:
- key : CA CA CA CA CA CA CA CA
- data : 0 0 0 0 0 0 0 0
- result: 57 87 D1 5F 28 6C 3A 3B
result is correct now and your code seems to be correct too.
regards,
Christophe.
-----Message d'origine-----
De : Lim Kelvin [mailto:[EMAIL PROTECTED]]
Envoy� : mardi 3 juillet 2001 11:12
� : [EMAIL PROTECTED]
Objet : [OCF] HELP!!! GemXpresso SINGLE DES encryption
Hi,
I need help on the single des encryption. I am
currently using the below configuration.
- GemXpresso
- GSE Simulation
- JDK 1.2.2
I have created a single DES function. However, I am
unable to get the right encryption out from it. Below
are the data:
- key : 0 0 0 0 0 0 0 0
- data : 0 0 0 0 0 0 0 0
- encryted data return by the GSE
57 87 D1 5F 28 6C 3A 3B (wrong)
- expected data needed
8C A6 4D E9 C1 B1 23 A7
The function is added into the OPPurse example
supplied by Gemplus. Was there something that I have
missed out?
Below is part of function I have added :
// this will set the DES3 key , supply the des3
key using APDU command
private void setDesKey( APDU apdu ){
byte[] apduBuffer = apdu.getBuffer() ;
if( apduBuffer[4] !=(short) 8 ||
apdu.setIncomingAndReceive()!=(short)8 ){
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
Util.arrayCopyNonAtomic(apduBuffer,(short)5,desKeyBuffer,(short)0,(short)8);
}
//this will encrypt the apdu data using the des3
key
private void encrypt(APDU apdu ){
byte[] apduBuffer = apdu.getBuffer() ;
short len = apdu.setIncomingAndReceive();
DESKey singleDESKey = returnDESKey();
byte [] result =
encryptData(apduBuffer,len,apdu,singleDESKey);
returnByteArray(apdu,result);
}
private byte[] encryptData(byte[] datain ,short
length,APDU apdu,DESKey key){
byte [] result = JCSystem.makeTransientByteArray
(length,JCSystem.CLEAR_ON_DESELECT);
Cipher c =
Cipher.getInstance(Cipher.ALG_DES_CBC_NOPAD ,true);
c.init(key , Cipher.MODE_ENCRYPT);
c.dofinal(datain,(short)5,length,result,(short)0);
return result;
}
private DESKey returnDESKey(){
DESKey deskey ;
deskey =(DESKey)KeyBuilder.buildKey
(KeyBuilder.TYPE_DES_TRANSIENT_RESET
,KeyBuilder.LENGTH_DES ,false);
deskey.setKey(desKeyBuffer ,(short)0);
return deskey;
}
private void returnByteArray(APDU apdu, byte[]
outData){
Util.arrayCopyNonAtomic(outData,(short)0,apdu.getBuffer(),
(short)5,(short)outData.length);
apdu.setOutgoing() ; // Switches to output mode
apdu.setOutgoingLength((short)outData.length ) ;
// bytes to return
apdu.sendBytes( (short)5, (short)outData.length
);//
}
With Regards,
Kelvin Lim
____________________________________________________________________________
_
http://messenger.yahoo.com.au - Yahoo! Messenger
- Voice chat, mail alerts, stock quotes and favourite news and lots more!
---
> 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.
---
> 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.