Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

DES Encrypt/Decrypt

Algorithm School

Moderator: UNKNwYSHSA

Danieken
Posts: 19
Joined: Thu Sep 17, 2015 10:28 pm
Points :101
Contact:

DES Encrypt/Decrypt

Post by Danieken » Wed Mar 23, 2016 7:48 am

I have completed an applet. But when I run my code, JCWDE answer to me with this Status Word: 00 05. That is Illegal Use. Could anyone give me any advice or comments? thx

Here is my code.

Code: Select all

byte[] key1 = {(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11};
byte[] cipherText = {(byte)0x9e,(byte)0x90,(byte)0xde,(byte)0x82,(byte)0x74,(byte)0x5e,(byte)0x78,(byte)0x52};
byte[] plainText = new byte[(short)8];

DESKey deskey =  (DESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_DES,KeyBuilder.LENGTH_DES, false); 

desKey.setKey(key1,(short)0);

Cipher cipherDES = Cipher.getInstance(Cipher.ALG_DES_CBC_ISO9797_M2 , false);

cipherDES.init(deskey ,Cipher.MODE_DECRYPT);

try
{
     cipherDES.doFinal(cipherText, (short)0, (short)cipherText.length, plainText, (short)0 );
}
catch(CryptoException c)
{
     if(c.getReason()==CryptoException.UNINITIALIZED_KEY)
          ISOException.throwIt(CryptoException.UNINITIALIZED_KEY);
         
     else if (c.getReason()==CryptoException.ILLEGAL_USE)
          ISOException.throwIt(CryptoException.ILLEGAL_USE);
               
     else if(c.getReason()==CryptoException.INVALID_INIT)
          ISOException.throwIt(CryptoException.INVALID_INIT);
}

Tarantino
Posts: 101
Joined: Wed Aug 19, 2015 1:56 am
Points :478
Contact:

Re: DES Encrypt/Decrypt

Post by Tarantino » Wed Mar 23, 2016 8:32 am

Is cipherText correct? As I know, one of the ILLEGAL_USE exception reasons is that padding is incorrect.
The greatest glory in living lies not in never falling, but in rising every time we fall.--Nelson Mandela

Danieken
Posts: 19
Joined: Thu Sep 17, 2015 10:28 pm
Points :101
Contact:

Re: DES Encrypt/Decrypt

Post by Danieken » Wed Mar 23, 2016 8:49 am

Tarantino wrote:Is cipherText correct? As I know, one of the ILLEGAL_USE exception reasons is that padding is incorrect.


I have crypted this

Code: Select all

byte[] plainText = {(byte)0x11,(byte)0x22,(byte)0x33,(byte)0x44,(byte)0x55,(byte)0x66,(byte)0x77,(byte)0x88};


with this key:

Code: Select all

byte[] key = {(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11};


the Result is:

Code: Select all

byte[] cipherText = {(byte)0x9e,(byte)0x90,(byte)0xde,(byte)0x82,(byte)0x74,(byte)0x5e,(byte)0x78,(byte)0x52,(byte)0x1c,(byte)0xd6,(byte)0xc3,(byte)0xf6,(byte)0xea,(byte)0x4d,(byte)0x9d,(byte)0x64};


But what do I have to pass to the doFinal() method, in order to obtain the plaintext from the ciphertext?

Tarantino
Posts: 101
Joined: Wed Aug 19, 2015 1:56 am
Points :478
Contact:

Re: DES Encrypt/Decrypt

Post by Tarantino » Thu Mar 24, 2016 9:01 am

You have to pass full encrypted string, it is 16 byte length because padding was added before encryption.
The greatest glory in living lies not in never falling, but in rising every time we fall.--Nelson Mandela

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 19 guests

JavaCard OS : Disclaimer