Page 1 of 1

How to Store a String data into the Java Card

Posted: Fri Feb 22, 2019 10:48 pm
by herry
I need to know how to store String data in my JavaCard、any help please :?: :?:

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

Posted: Sat Feb 23, 2019 12:18 pm
by kuafu
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

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

Posted: Sat Feb 23, 2019 11:20 pm
by kuafu
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;

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

Posted: Mon Feb 25, 2019 6:31 am
by BirdKing
Javacard has string class. You may consider your need carefully.

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

Posted: Mon Feb 25, 2019 7:06 am
by kuafu
Javacard has string class,that's true. But it didn't support by most cards in the market.