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.

Reply via email to