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.

3DES

JavaCard Applet Development Related Questions and Answers.
deepanshsinghal
Posts: 44
Joined: Thu Apr 06, 2017 8:01 am
Points :460
Contact:

Re: 3DES

Post by deepanshsinghal » Wed May 31, 2017 12:25 am

UNKNwYSHSA wrote:
deepanshsinghal wrote:I tried with openemv implementation also... but no success


Can you tell me, how do you verify the result? And i will have a try to resolve this problem. I have no terminate application to verify the applet functions. :?


There is BP-Tool you can use that to verify
Check out this link " https://eftlab.co.uk/index.php/downloads/bp-tools " you'll get that Tool

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: 3DES

Post by UNKNwYSHSA » Wed May 31, 2017 1:33 am

OK, let me hava a try.
sense and simplicity

deepanshsinghal
Posts: 44
Joined: Thu Apr 06, 2017 8:01 am
Points :460
Contact:

Re: 3DES

Post by deepanshsinghal » Wed May 31, 2017 1:46 am

UNKNwYSHSA wrote:OK, let me hava a try.


Thanks, any help from you is appreciated

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: 3DES

Post by UNKNwYSHSA » Wed May 31, 2017 1:50 am

:D
sense and simplicity

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: 3DES

Post by UNKNwYSHSA » Wed May 31, 2017 5:51 am

Which version of EMV specification are you watching?
The session key can be calculated and same as the tool's result.
But the AC, ..., always different!
sense and simplicity

deepanshsinghal
Posts: 44
Joined: Thu Apr 06, 2017 8:01 am
Points :460
Contact:

Re: 3DES

Post by deepanshsinghal » Wed May 31, 2017 5:56 am

UNKNwYSHSA wrote:Which version of EMV specification are you watching?
The session key can be calculated and same as the tool's result.
But the AC, ..., always different!


EMV 4.3 Book 2 Security and Key Management (8.1.1) as per you suggested with that i am generating AC with BP-Tool and i have one java program which calculate compute AC.. .... Both results are same.

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: 3DES

Post by UNKNwYSHSA » Wed May 31, 2017 6:16 am

You need to see Version 4.2. Not 4.3. Can you send your java programe to me? The java programe can be decompiled and we can know how it works.
sense and simplicity

deepanshsinghal
Posts: 44
Joined: Thu Apr 06, 2017 8:01 am
Points :460
Contact:

Re: 3DES

Post by deepanshsinghal » Wed May 31, 2017 6:24 am

UNKNwYSHSA wrote:You need to see Version 4.2. Not 4.3. Can you send your java programe to me? The java programe can be decompiled and we can know how it works.


But the concept to generate the AC will be the same no matter it is 4.2 or 4.3

Code: Select all

   public static byte[] computeMAC(byte[] key, byte[] plaintext) {

      System.out.println("MAC : key " + Arrays.toString(key));
      System.out.println("MAC : plaintext " + Arrays.toString(plaintext));
      byte[] ka = new byte[8];
      System.arraycopy(key, 0, ka, 0, 8);
      byte[] kb = new byte[8];

      System.arraycopy(key, 8, kb, 0, 8);

      SecretKey skeya = new SecretKeySpec(ka, "DES");
      SecretKey skeyb = new SecretKeySpec(kb, "DES");
      byte[] current = new byte[8];
      byte[] mac = new byte[] { (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 };

      System.out.println("KEY " + Utils.toHexString(key));
      System.out.println("DATA " + Utils.toHexString(plaintext));
      plaintext = padding(plaintext);
      System.out.println("AP DATA " + Utils.toHexString(plaintext));
      Cipher des;
      try {
         for (int i = 0; i < plaintext.length; i += 8) {
            System.out.println("8 BYTES " + current);
            System.arraycopy(plaintext, i, current, 0, 8);
            mac = xor(current, mac);
            des = Cipher.getInstance("DES/CBC/NoPadding");
            des.init(Cipher.ENCRYPT_MODE, skeya, new IvParameterSpec(new byte[8]));
            mac = des.doFinal(mac);
         }
         des = Cipher.getInstance("DES/CBC/NoPadding");
         des.init(Cipher.DECRYPT_MODE, skeyb, new IvParameterSpec(new byte[8]));
         mac = des.doFinal(mac);

         des.init(Cipher.ENCRYPT_MODE, skeya, new IvParameterSpec(new byte[8]));
         mac = des.doFinal(mac);
      } catch (Exception e) {
         e.printStackTrace();
      }
      return mac;
   }

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: 3DES

Post by UNKNwYSHSA » Wed May 31, 2017 11:37 pm

deepanshsinghal wrote:
UNKNwYSHSA wrote:You need to see Version 4.2. Not 4.3. Can you send your java programe to me? The java programe can be decompiled and we can know how it works.


But the concept to generate the AC will be the same no matter it is 4.2 or 4.3

Code: Select all

   public static byte[] computeMAC(byte[] key, byte[] plaintext) {

      System.out.println("MAC : key " + Arrays.toString(key));
      System.out.println("MAC : plaintext " + Arrays.toString(plaintext));
      byte[] ka = new byte[8];
      System.arraycopy(key, 0, ka, 0, 8);
      byte[] kb = new byte[8];

      System.arraycopy(key, 8, kb, 0, 8);

      SecretKey skeya = new SecretKeySpec(ka, "DES");
      SecretKey skeyb = new SecretKeySpec(kb, "DES");
      byte[] current = new byte[8];
      byte[] mac = new byte[] { (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 };

      System.out.println("KEY " + Utils.toHexString(key));
      System.out.println("DATA " + Utils.toHexString(plaintext));
      plaintext = padding(plaintext);
      System.out.println("AP DATA " + Utils.toHexString(plaintext));
      Cipher des;
      try {
         for (int i = 0; i < plaintext.length; i += 8) {
            System.out.println("8 BYTES " + current);
            System.arraycopy(plaintext, i, current, 0, 8);
            mac = xor(current, mac);
            des = Cipher.getInstance("DES/CBC/NoPadding");
            des.init(Cipher.ENCRYPT_MODE, skeya, new IvParameterSpec(new byte[8]));
            mac = des.doFinal(mac);
         }
         des = Cipher.getInstance("DES/CBC/NoPadding");
         des.init(Cipher.DECRYPT_MODE, skeyb, new IvParameterSpec(new byte[8]));
         mac = des.doFinal(mac);

         des.init(Cipher.ENCRYPT_MODE, skeya, new IvParameterSpec(new byte[8]));
         mac = des.doFinal(mac);
      } catch (Exception e) {
         e.printStackTrace();
      }
      return mac;
   }


Waiting your java programme.
sense and simplicity

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: 3DES

Post by UNKNwYSHSA » Thu Jun 01, 2017 4:43 am

I got that!!!

Steps:
1 Encrypt data blocks using first des key with cbc mode;
2 Decrypt the result with second des key;
3 Encrypt the result of step 2 with first des key;
The AC calculated.

Example:
Session key: 7CBA97ABD6CB6E0B 29A7457A7332DFC4
Fist des key: 7CBA97ABD6CB6E0B
Second des key: 29A7457A7332DFC4
Data: Terminal Data + ICC Data + 800000(Pad)
Data: 0000000010000000000000000710000000000007101302050030901B6A + 3C00005503A4A082 + 800000

Calculate:
1Key: 7CBA97ABD6CB6E0B
IV: 0000000000000000
m: 0000000010000000000000000710000000000007101302050030901B6A3C00005503A4A082800000
s: AB45C4A8204CA392374F2F5FCAE5A8A2E18B65F7554966C5E3697C946CD8B284EFC6ECB7A354B1CA
2 Key: 29A7457A7332DFC4
IV: 0000000000000000
m: EFC6ECB7A354B1CA
s: 388B6AA70A89AB7C
3 Key: 7CBA97ABD6CB6E0B
IV: 0000000000000000
m: 388B6AA70A89AB7C
s: 50C221AF54C1706A
The result is: 50C221AF54C1706A

Same as the tool calculated.
Session key: 7CBA97ABD6CB6E0B29A7457A7332DFC4
Terminal data: 0000000010000000000000000710000000000007101302050030901B6A
ICC data: 3C00005503A4A082
Padding method: Method 2 (EMV spec or e.g. VISA CV14)
----------------------------------------
AC generated: 50C221AF54C1706A


Note:
The implementation of this algorithm in javacard is: Signature.ALG_DES_MAC8_ISO9797_1_M2_ALG3
sense and simplicity

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 47 guests

JavaCard OS : Disclaimer