Page 1 of 1
How to Write on a smart card?
Posted: Wed Oct 28, 2015 4:20 pm
by setayesh
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
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 .
Re: How to Write on a smart card?
Posted: Wed Oct 28, 2015 11:09 pm
by mabel
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=1152.
http://ftp.cis.nctu.edu.tw/csie/Documen ... sGuide.pdf3.
viewtopic.php?f=31&t=68
Re: How to Write on a smart card?
Posted: Sat Oct 31, 2015 3:27 pm
by setayesh
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=f01ea5b8103491388b87eb56dd165e91like 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 ?
Re: How to Write on a smart card?
Posted: Mon Nov 02, 2015 2:36 am
by mabel
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.
Re: How to Write on a smart card?
Posted: Mon Nov 02, 2015 3:53 am
by Tolice
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".
Re: How to Write on a smart card?
Posted: Mon Nov 16, 2015 3:32 am
by setayesh
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
Re: How to Write on a smart card?
Posted: Mon Nov 16, 2015 3:38 am
by setayesh
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;
}
}