How to Store a String data into the Java Card

JavaCard Applet Development Related Questions and Answers.
herry
Posts: 15
Joined: Thu Jul 19, 2018 2:36 am
Points :208
Contact:

How to Store a String data into the Java Card

Post by herry » Fri Feb 22, 2019 10:48 pm

I need to know how to store String data in my JavaCard、any help please :?: :?:

kuafu
Posts: 150
Joined: Thu Jun 25, 2015 2:09 am
Points :1613
Contact:

Re: How to Store a String data into the Java Card

Post by kuafu » Sat Feb 23, 2019 12:18 pm

On PC,convert String to byte stream, and transitive to card. Store byte stream with a byte array object.

1,PC : String —-> byte stream. ——-> Card

2.Card: byte stream ——> PC

3. PC : byte stream ——>String
well

kuafu
Posts: 150
Joined: Thu Jun 25, 2015 2:09 am
Points :1613
Contact:

Re: How to Store a String data into the Java Card

Post by kuafu » Sat Feb 23, 2019 11:20 pm

On PC

Code: Select all

    public static void main(String[] arguments) {
    	String sss = "string to byte stream";
    	byte[] byte_stream = sss.getBytes();
        // send  byte_stream to  card
    	
        //  do the transmit procession
    	
    	// receive byte_steam from card ;
    	
    	String recovery = new String(byte_stream);
    	System.out.println(recovery);
    }
On card

Code: Select all

        case (byte)INS_SEND_RECV_APDU_1:
            //Define a byte string
            byte sendStr[] = {'A','P','D','U', ',', 'C','l','a','s','s', ',', 'D','e','m','o'};
            short len = (short) sendStr.length;
 
            //Copy character to APDU Buffer.
            Util.arrayCopyNonAtomic(sendStr, (short)0, buf, (short)0, (short)len);
 
            //Send the 'sendStr' string, the hex of JCRE sending data is the ASCII of sendStr.
            apdu.setOutgoingAndSend((short)0, (short)len);
            break;
well

BirdKing
Posts: 72
Joined: Wed Nov 04, 2015 7:23 am
Points :524
Contact:

Re: How to Store a String data into the Java Card

Post by BirdKing » Mon Feb 25, 2019 6:31 am

Javacard has string class. You may consider your need carefully.

kuafu
Posts: 150
Joined: Thu Jun 25, 2015 2:09 am
Points :1613
Contact:

Re: How to Store a String data into the Java Card

Post by kuafu » Mon Feb 25, 2019 7:06 am

Javacard has string class,that's true. But it didn't support by most cards in the market.
well

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 4 guests

JavaCard OS : Disclaimer