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.

How to Write on a smart card?

JavaCard Applet Development Related Questions and Answers.
setayesh
Posts: 4
Joined: Tue Oct 27, 2015 8:53 am
Points :0
Contact:

How to Write on a smart card?

Post by setayesh » Wed Oct 28, 2015 4:20 pm

My master gave me a smart card and a card reader with a Java application.
And I have a week to explain how to read and write on the card, while I am a beginner programmers in Java :cry:
Who can help me? Is there a book or an article about this topic?
I've downloaded some paper, but nobody did not explain how to write on the smart card.
Please help me , thanks in advance .

User avatar
mabel
Posts: 237
Joined: Mon May 18, 2015 3:09 am
Points :1705
Contact:

Re: How to Write on a smart card?

Post by mabel » Wed Oct 28, 2015 11:09 pm

Are you referring to upload and install the applet into your smartcard?
If Yes, you can use PyAPDUTool to do this. And then send/receive APDU command to communicate with your applet via this tool.

If you need to develop an applet by yourself, this tool can help.

In addition, you can look through these guide to get started with javacard.
1. viewtopic.php?f=31&t=115
2. http://ftp.cis.nctu.edu.tw/csie/Documen ... sGuide.pdf
3. viewtopic.php?f=31&t=68

setayesh
Posts: 4
Joined: Tue Oct 27, 2015 8:53 am
Points :0
Contact:

Re: How to Write on a smart card?

Post by setayesh » Sat Oct 31, 2015 3:27 pm

mabel wrote:Are you referring to upload and install the applet into your smartcard?
If Yes, you can use PyAPDUTool to do this. And then send/receive APDU command to communicate with your applet via this tool.

If you need to develop an applet by yourself, this tool can help.



Thanks for reply

I had a error in step 3 in this page > http://javacardos.com/javacardforum/viewtopic.php?f=3&t=38&sid=f01ea5b8103491388b87eb56dd165e91
like this :
Download Cap begin...
Download Cap error: Check Card Cryptogram failed.

but my master told me anything about encryption.

However , i use this cap file for test >> JavaCardKit\SDK\Tools\WalletDemo\WalletDemoApplet.cap <<

I thought , i should made a cap file from my java program.
I've downloaded this tool >> http://eclipse-jcde.sourceforge.net/user-guide.htm << from this answer >> http://stackoverflow.com/questions/24127342/creating-a-cap-file-with-jcdk << , but i can't make a cap file.When I open Eclipse , convert button is off.
How do I make a cap file , for my program ?

User avatar
mabel
Posts: 237
Joined: Mon May 18, 2015 3:09 am
Points :1705
Contact:

Re: How to Write on a smart card?

Post by mabel » Mon Nov 02, 2015 2:36 am

I use JCIDE to build my applet and JCIDE shall generate the CAP file automatically under the project path(e.g. C:\workspace\test\bin\patest\javacard) if your project is built successfully.
So if you just want to get the CAP file, just create a project in JCIDE , paste you applet code and build your project, then you can get your CAP file.

User avatar
Tolice
Posts: 40
Joined: Wed May 20, 2015 2:41 am
Points :254
Contact:

Re: How to Write on a smart card?

Post by Tolice » Mon Nov 02, 2015 3:53 am

Download Cap error: Check Card Cryptogram failed.

You can switch to the BaseAPDU page in output, view the APDU while downloading cap file.
Maybe the key of this card you used is changed, you can check if the key is the default "404142434445464748494A4B4C4D4E4F".

setayesh
Posts: 4
Joined: Tue Oct 27, 2015 8:53 am
Points :0
Contact:

Re: How to Write on a smart card?

Post by setayesh » Mon Nov 16, 2015 3:32 am

mabel wrote:I use JCIDE to build my applet and JCIDE shall generate the CAP file automatically under the project path(e.g. C:\workspace\test\bin\patest\javacard) if your project is built successfully.
So if you just want to get the CAP file, just create a project in JCIDE , paste you applet code and build your project, then you can get your CAP file.


tnx for reply
when i paste my program , it has 44 errors :.

like that

C:\WORKSP~1\new\src\com\netrise\sc\SmartCard.java:4: package javax.smartcardio does not exist


and i cant find this package.

when i merge all packages , it has one error .
like that
error: cannot read: ByteUtil.java

setayesh
Posts: 4
Joined: Tue Oct 27, 2015 8:53 am
Points :0
Contact:

Re: How to Write on a smart card?

Post by setayesh » Mon Nov 16, 2015 3:38 am

And this is ByteUtil :

Code: Select all

package com.netrise.util;

import java.io.UnsupportedEncodingException;

public class ByteUtil {

   public static byte[] extract(byte[] data, int start, int length) {
      
      byte[] result = new byte[length];
      int pointer = 0;
      for (int i = 0; i < data.length; i++) {
         byte b = data[i];
         if (i >= start && i < start + length) {
            result[pointer] = b;
            pointer++;
         }
      }
      
      return result;
      
   }
   
   public static String arrayToHex(byte[] data)  {
      StringBuffer sb = new StringBuffer();
      for (int i = 0; i < data.length; i++) {
         String bs = Integer.toHexString(data[i] & 0xFF);
         if (bs.length() == 1) {
            sb.append(0);
         }
         sb.append(bs);
      }
      
      return sb.toString();
   }   

   public static byte[] AsciiStringToBytes(String text) {
      if (text == null || text.length() < 1) {
         return new byte[0];
      }
      
      return text.getBytes();
   }

   public static String BytesToAsciiString(byte[] Data) {
      try {
         String s = new String(Data, 0 , Data.length , "ASCII");
         return s;
      }
      catch(UnsupportedEncodingException e) {
         e.printStackTrace();
      }
      
      return " ";
   }

   public static byte[] UTF16StringToBytes(String text) {
      byte[] buff;
      
      try {
         buff = text.getBytes("UTF-16");
      }
      catch(UnsupportedEncodingException e) {
         System.out.println(e.getMessage());
         buff = null;
      }
      
      return buff;
   }
   
   public static String BytesToUTF16String(byte[] Bytes) {
      try {
         String s = new String(Bytes, 0 , Bytes.length , "UTF-16");
         return s;
      }
      catch(UnsupportedEncodingException e) {
         e.printStackTrace();
      }
      
      return null;
   }

   public static byte[] UTF8StringToBytes(String text) {
      if (text == null || text.length() < 1) {
         return new byte[0];
      }

      byte[] buff;
      
      try {
         buff = text.getBytes("UTF-8");
      }
      catch(UnsupportedEncodingException e) {
         e.printStackTrace();
         buff = null;
      }
      
      return buff;
   }
   
   public static String BytesToUTF8String(byte[] Bytes) {
      try {
         String s = new String(Bytes, 0 , Bytes.length , "UTF-8");
         return s;
      }
      catch(UnsupportedEncodingException e) {
         e.printStackTrace();
      }
      
      return null;
   }
   
   public static byte[] resizeArray(byte[] oldArray, int newSize) {
      int oldSize = oldArray.length;
      byte[] newArray = new byte[newSize];
      int preserveLength = Math.min(oldSize, newSize);
      if (preserveLength > 0) {
         System.arraycopy(oldArray, 0, newArray, 0, preserveLength);
      }
      
      return newArray;
   }
   
   public static byte[] resizeArray(Object[] oldArray, int newSize) {
      int oldSize = oldArray.length;
      byte[] newArray = new byte[newSize];
      int preserveLength = Math.min(oldSize, newSize);
      if (preserveLength > 0) {
         System.arraycopy(oldArray, 0, newArray, 0, preserveLength);
      }
      
      return newArray;
   }
   
}

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 19 guests

JavaCard OS : Disclaimer