Generate DES key with java card with JCRE 2.1.2

Hi everyone,
I want to generate DES key in my applet . my card supports GP 2.0.1 and JCRE 2.1.2 .
I have tested my applet with JCRE 2.2.1 and used this JCSystem class functions to generate DES key and it compiles and works correctlly .
but when I want to compile my applet with JCRE 2.1.2 I recieve an error which says that API 2.1.2 doesn't support JCSystem class .
so I'll really appreciate it if anyone could tell me how can I generate DES key with JCRE 2.1.2
and also I use JCSystem class functions to get my card's persistent and transistent memory , so with this class not working on JCRE 2.1.2 I have problem to read my free memories too .
So I'll appreciate your help on this matter too.
Best Regards,
Vivian

Hi Vivian,
I don't seem to have any problem with the code you posted. What is the error you are getting? Is it with the compiler or with the CAP file converter? If it is a compiler error, you will need to ensure that the Java Card API jar is in your build path.
Here is a simple class that works with JC 2.1.1 (which will work with JC 2.1.2 as well). I have confirmed that this applet compiles and will return encrypted data to the caller.
package test;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.JCSystem;
import javacard.security.DESKey;
import javacard.security.KeyBuilder;
import javacard.security.RandomData;
import javacardx.crypto.Cipher;
* Test JC2.1.1 applet for random DES key.
* @author safarmer - 1.0
* @created 24/11/2009
* @version 1.0 %PRT%
public class TestApplet extends Applet {
    private DESKey key;
    private Cipher cipher;
     * Default constructor that sets up key and cipher.
    public TestApplet() {
        RandomData rand = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
        short lenBytes = (short) (KeyBuilder.LENGTH_DES / 8);
        byte[] buffer = JCSystem.makeTransientByteArray(lenBytes, JCSystem.CLEAR_ON_DESELECT);
        key = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES, false);
        rand.generateData(buffer, (short) 0, lenBytes);
        key.setKey(buffer, (short) 0);
        cipher = Cipher.getInstance(Cipher.ALG_DES_CBC_ISO9797_M1, false);
    public static void install(byte[] bArray, short bOffset, byte bLength) {
        // GP-compliant JavaCard applet registration
        new TestApplet().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
    public void process(APDU apdu) {
        // Good practice: Return 9000 on SELECT
        if (selectingApplet()) {
            return;
        byte[] buf = apdu.getBuffer();
        switch (buf[ISO7816.OFFSET_INS]) {
            case (byte) 0x00:
                cipher.init(key, Cipher.MODE_ENCRYPT);
                short len = cipher.doFinal(buf, ISO7816.OFFSET_CDATA, buf[ISO7816.OFFSET_LC], buf, (short) 0);
                apdu.setOutgoingAndSend((short) 0, len);
                break;
            default:
                // good practice: If you don't know the INStruction, say so:
                ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}Cheers,
Shane

Similar Messages

  • How could I generate RSA Key on Java Card

    I am coding program base on javacard .
    I can generate DES Key ,but I can't generate RSA key.
    Any help is appreiciated.
    Thanks in advance.
    Regards.

    I think you need a '3rd party' for this, I'm pretty sure that there is no in-built support for RSA - though there is Diffie-Hellman.

  • Java application communicate with java card applet without java card

    Can I write java application to communicate with java card applet without using java card?
    Can I send APDU to java card applet on computer(not install in java card)? If it's not, how can I write?
    Best Regard,
    Thanawan

    Your JCOP simulator implements a JCVM/JCRE according
    to specs. The CREF does that same thing excepts it's
    only simulates the API without crypto or third party
    applets. JCOP simulator is more then that. They are using thesame_ codebase for simulator and for oncard JCVM. Basically you are dealing with the same environment in both cases.

  • Can  i use SLE4428 smart card with java card developmentkit 2.1.2

    Can i use SLE4428 smart card with java card developmentkit 2.1.2
    plz reply

    No. SLE4428 is memory card and not Java Card.

  • Need help for equipments for java card with RFID technology .

    I 'm doin a project using java card with RFID technology.Can ne one give me exact equipments for java card reader & writer for RFID technology?
    I need to buy these things from UK.Can ne one provide me some product list & as well as the exact pricelist?
    plz reply me asap.

    I 'm doin a project using java card with RFID
    technology.Can ne one give me exact equipments for
    r java card reader & writer for RFID technology?I guess with "RFID" you are referring to "contact-less javacards"?
    If yes, one keyword for you is "Mifare", a industry standard for smartcards with dual interface (contact-based and contactless).
    Jan

  • External Authentication with Java Card through HSM

    Hi All,
    How to do External Authentication process in Javacard through HSM (Hardware Security Module). Does any HSM supports this?
    My requirement is to store the Card KMC in HSM and i should authenticate the terminal application with the Java Card through HSM.
    Does anyone have the idea on this. Because i should not expose the Card KMC to outside world.

    Hi,
    Megaa1207 wrote:
    My requirement is to store the Card KMC in HSM and i should authenticate the terminal application with the Java Card through HSM.If you cannot create a functional module for your HSM to perform external authenticate, you can use the PKCS11 libraries (cryptoki) to perform the primitive operations to generate your KDC's and to use them for generating session keys and cryptograms. All the sensitive data will be able to stay secured inside the HSM. You would perform the cryptographic operations on the derivation data and store the result as a key object inside the HSM. There is quite a lot of documentation on the PKCS11 operations on the RSA web site.
    Cheers,
    Shane

  • 3000 usd reward for the one can provide me any JAVA card with AES

    Hello,
    i am quite desperate, i am trying to find 1000-2000 java cards (schlumberger or jcop) with AES enabled. Seems this cards are really hard to find, i got allready offers and samples but all of them without AES enabled.
    I am willing offer 3000 USD reward to the person can give me the right contact where i can get those cards (at least 1000 pices) till 25-th of September. I got allready one offer from sagem orga for jcop, but their delivery time is 4-6 weeks, so it must be some one have such qtty of cards fizicaly on hand ready to ship.
    Please contact me by PM or phone (+852-6723-9999) or post here your contact details and i am calling you back.
    Thanks and best regards,
    Razvan

    @clemson
    i also have offer from sagem orga, delivery time 4-6 weeks, the point is that my customer does not understand that it is just a question of luck to find some one with cards on stock, he wants his goods fast. I have told him from begining not to stick on one specific card, but he preferred using jcop. I got some jcop from an analphabet, 10K pcs, jcop41 and this analphabet promised us to deliver us version 2.3.1, but the cards he delivered to us were 2.2.1 and those do not have AES !!!
    This is the reason why i am offering this reward. Maybe some one knows some one who have stock of 1000-2000 pcs. Now my customer does not mind to use ANY JAVA CARD which have AES. He don't mind if those cards are from Oberthur, Nxp, Gemalto, Giesecke & Devrient, or other manufacturer. His requirements are: a) must be java card b)must have AES other features are not important.
    Reagards,
    Razvan

  • I dont install the wallet sample to java card with gpshell . help please .?

    Hi
    I use Gemalto pc twin Reader.
    I try jdks(1.3.5 , 1.5 , 1.6 versions) for compile
    I use java card kit (2.1.1 , 2..1.2 , 2.2.1 ,2.2.2 versions) for create cap files
    For loadin used gpshell (1.4.2 , 1.4.1 , 1.3.1 versions)
    script
    enable_trace
    establish_context
    card_connect
    select -AID a0000000030000
    open_sc -security 1 -keyind 0 -keyver 0 -mac_key 404142434445464748494a4b4c4d4e4f -enc_key 404142434445464748494a4b4c4d4e4f // Open secure channel
    install_for_load -pkgAID a00000006203010C06 -nvCodeLimit 500 -sdAID A000000003000000
    load -file wallet.cap
    install_for_install -priv 02 -AID a00000006203010C0601 -pkgAID a00000006203010C06 -instAID a00000006203010C0601 -nvDataLimit 500
    get_status -element 20                                   
    card_disconnect
    release_context
    I didnt load wallet applet to card. Some time I take install_for_load error , some time install_for_install_and_make_selectable()
    Please help me.
    With jdk 1.3_5 , java card dev kit 2.1.2 and gpshell , I load applet to card but dont install and I take install_for_install_and_make_selectable returns 0x80206A80 (6A80 : Wrong data / incorrect values in command data) error.
    I dont understand why dont loaded the applet to card. Actually I load and install HelloWorld.cap file as this way.
    Additionally , In the wallet applet , the register method used as resigter(bArray , ..... .

    Anybody help me please. It very important. :(

  • Java Card with USB interface

    Hi,
    I'm trying to use a Java Card for a project I'm doing at the university. But one of our requirements is to use a one with a USB interface +(ie: without the need for a separate smart card reader).+
    Have anyone come across such a device that is with a USB interface. If so please provide me with links.
    Thanks in advance.
    Regards,
    NiMaL

    ID-1 Format:
    NXP (Philips) JCOP 41 V2.2.1/72K USB
    http://tinyurl.com/6oz9qq
    OMNIKEY CardMan 1109 USB Connector
    http://tinyurl.com/5zvg34
    ID-0 Format:
    NXP JCOP 41 V2.2.1/72K USB SIM format
    http://tinyurl.com/5abxxj
    Gemalto Reflex 531 USB SIM Token Connector
    http://tinyurl.com/5j9e5p
    SIM card retainer/Surface mount type
    http://tinyurl.com/63buqy

  • Compiling java card with Eclipse

    Hi,
    I compiled and converted Java card code both from the command prompt and Eclipse in Windows XP and it worked just fine.
    However, while doing the same in Eclipse set up on a Linux(Ubuntu) machine, I am getting the following error:
    error: export file framework.exp of package javacard.framework not found.
    I have been searching around for answers to why this might be happening. However, I haven't found any. If anyone knows why, please help me out with this.
    Thanks a lot in advance.
    Best,

    Are you converting with an Eclipse plugin? If so what are you using?
    That error is because the converter can't find the EXP files from the JCDK. You may need to update a setting in the plugin to point to the JCDK.
    Cheers,
    Shane

  • Help with Java card client

    Hello All ,
    i am new to javacard ...
    i am using JCOP31 , and smartcard reader 5321
    and implementing the java card by using Eclipse with the JCOP tools plugin
    I installed an applet on a java card... and i was told that i have to write a client program to test it.
    I hope some one show me how to implement a javacard Client ..and what i should do to implement a JavaCard Client .
    Thank You for your time.

    Hi,
    Your best bet (for communicating with a real card) is to use the classes in the javax.smartcardio package in Java 6. If you search the forum you should be able to find examples of using this.
    If you need to communicate with the JCOP card simulator, you will need to use the JCOP offcard API's. This is a little bit harder and you will most likely have to use trial and error (and Eclipse) to find the classes you need. I have used this in the past, but I do not have any examples of this. It was actually possible to develop a service layer that can use either API so you can switch between a real card and JCOP simulator (handy for debugging). The JCOP offcard API jar file is in the JCOP Tools plugins directory.
    Cheers,
    Shane

  • Sim tool kit  with java card help

    Hi all,
    i want to develop an applet which sends a sms to the network using sim tool kit and java card. can anyone can help me on this?
    if u can give me any document or links or sampale codes i realy appriciate it.
    Nuwan Nanayakkara

    * Send message by SMS
    * @param message byte[] : message to send
    * @param number byte : number of the sms
    public void envoiSMS(byte[] message, byte number) {
    // sending of message with all needed parameters
    ProactiveHandler hdlerPro = ProactiveHandler.getTheHandler();
    short tpduSubmitLength = (short) (SERVER_ADDRESS.length + 6 +
    message.length);
    byte[] tpduSubmit = new byte[tpduSubmitLength];
    // TP-SRR + TP-UHDI + TP-RP + TP-VPF + TP-RD + TP-MTI
    //reply path(b) | user header indicator (b) | report request (b) | periode validity(2b) | rejet m�me numero MR(b) | message type (2b)
    byte FIRST_BYTE_local = (byte) 0x01; //juste type de message SUBMIT
    //tpduSubmit[0] = FIRST_BYTE; // TP-MTI + TP-RD + TP-VPF + TP-RP + TP-UDHI + TP-SRR
    tpduSubmit[0] = FIRST_BYTE_local;
    //tpduSubmit[1] = number;
    tpduSubmit[1] = 5;
    for (short i = 0; i < SERVER_ADDRESS.length; i++) {
    tpduSubmit[ (short) (i + 2)] = SERVER_ADDRESS;
    tpduSubmit[ (short) (SERVER_ADDRESS.length + 2)] = TP_PID;
    tpduSubmit[ (short) (SERVER_ADDRESS.length + 3)] = TP_DCS;
    tpduSubmit[ (short) (SERVER_ADDRESS.length + 4)] = (byte) message.length; //UDL
    for (short i = 0; i < message.length; i++) {
    tpduSubmit[ (short) (SERVER_ADDRESS.length + 5 + i)] = message[i]; //UD
    //envoi d'un SMS
    hdlerPro.init(PRO_CMD_SEND_SHORT_MESSAGE, (byte) 0, DEV_ID_NETWORK);
    hdlerPro.appendTLV(TAG_SMS_TPDU, tpduSubmit, (short) 0,
    (short) tpduSubmitLength);
    hdlerPro.send();
    I can't do all comments in english; another comments is in french.

  • Please help error regarding GPShell 1.4.2 with Java Card 2.2.1

    Hi masters..
    please help me regarding GPShell + Smart Card Reader (namely Omnikey Cardman 5321)..
    currently i've a smart card reader (Omnikey) and a sample java card that support for Java Card 2.2.1..
    i've installed Smart card reader's driver, and it has already completely function..
    When i try to run this command in GPShell 1.4.2, i get this report :
    C:\GPShell-1.4.2>GPShell helloInstallgemXpressoProR3_2E64.txt
    mode_201
    gemXpressoPro
    enable_trace
    establish_context
    card_connect
    * reader name OMNIKEY CardMan 5x21 0
    card_connect() returns 0x80100069 (The smart card has been removed, so that furt
    her communication is not possible.
    select -AID A000000018434D00
    Command --> 00A4040008A000000018434D00
    Wrapped command --> 00A4040008A000000018434D00
    select_application() returns 0x00000006 (The handle is invalid.
    Yes, i know that in that script (helloInstallgemXpressoProR3_2E64.txt), there's a script for load helloworld.cap into Java card..
    i tried that because i just want to make sure whether my Java Card run well or not..
    Please help me regarding this..
    Thanks in advance..

    Hi safarmer, thanks for your reply :)..
    Sorry before, i still don't understand about your last reply.. :(
    especially for check the crytpogram.. :(
    could you describe what mean of each line of code from that snippet code?..
    Sequence   : 0002
    challenge  : 598dd3961bfd
    cryptogram : 24cccf18c18437bb
    host       : 5a7787ba91497948
    DEBUG [] - Input to session S-ENC derivation: 01820002000000000000000000000000
    DEBUG [] - S-ENC: adc1163ba2a146fbb94af44c8676fb7cadc1163ba2a146fb
    DEBUG [] - Input to session DEK derivation : 01810002000000000000000000000000
    DEBUG [] - S-DEK: fd01086b6db03bdfe0d5cb61d03ed3abfd01086b6db03bdf
    DEBUG [] - Input to session CMAC derivation: 01010002000000000000000000000000
    DEBUG [] - S-MAC: 3e07b0c8fdfd798a573b9b9889d0cb513e07b0c8fdfd798a
    Input to card cryptogram verification: 5a7787ba914979480002598dd3961bfd8000000000000000
    DEBUG [] - Signature : 24cccf18c18437bb
    DEBUG [] - Cryptogram: 24cccf18c18437bb
    Card cryptogram authenticated=======================================================================================
    =======================================================================================
    i've added script "mode_211" to my script, as follow :
    mode_211
    enable_trace
    establish_context
    card_connect -readerNumber 2
    select -AID a0000000030000
    open_sc -security 1 -keyind 0 -keyver 0 -mac_key 404142434445464748494a4b4c4d4e4f -enc_key 404142434445464748494a4b4c4d4e4f // Open secure channel
    delete -AID a00000006203010c0101
    delete -AID a00000006203010c01
    delete -AID a00000006203010c0101
    install -file HelloWorld.cap -nvDataLimit 500 -instParam 00 -priv 2
    card_disconnect
    release_contextbut when i executed that script in the console, i got this :
    C:\GPShell-1.4.2>GPShell helloInstallChan.txt
    mode_211
    enable_trace
    establish_context
    card_connect -readerNumber 2
    * reader name OMNIKEY CardMan 5x21-CL 0
    select -AID a0000000030000
    Command --> 00A4040007A0000000030000
    Wrapped command --> 00A4040007A0000000030000
    Response <-- 6F108408A000000003000000A5049F6501FF9000
    open_sc -security 1 -keyind 0 -keyver 0 -mac_key 404142434445464748494a4b4c4d4e4
    f -enc_key 404142434445464748494a4b4c4d4e4f // Open secure channel
    Command --> 80CA006600
    Wrapped command --> 80CA006600
    Response <-- 664C734A06072A864886FC6B01600C060A2A864886FC6B02020101630906072A864
    886FC6B03640B06092A864886FC6B040215650B06092B8510864864020102660C060A2B060104012
    A026E01029000
    Command --> 80500000083C4E03633407EC1800
    Wrapped command --> 80500000083C4E03633407EC1800
    Response <-- 0000715457173C2B8FC1FF020002598DD3961BFD8B6F2963C070FF949000
    Command --> 8482010010E17B69E2A3DFEA320B0B457657362614
    Wrapped command --> 8482010010E17B69E2A3DFEA320B0B457657362614
    Response <-- 9000
    delete -AID a00000006203010c0101
    Command --> 80E400800C4F0AA00000006203010C010100
    Wrapped command --> 84E40080144F0AA00000006203010C0101D259A163E654B99900
    Response <-- 6A88
    delete_applet() returns 0x80206A88 (6A88: Referenced data not found.)
    delete -AID a00000006203010c01
    Command --> 80E400800B4F09A00000006203010C0100
    Wrapped command --> 84E40080134F09A00000006203010C01094A9BF13AD2CC3E00
    Response <-- 6A88
    delete_applet() returns 0x80206A88 (6A88: Referenced data not found.)
    delete -AID a00000006203010c0101
    Command --> 80E400800C4F0AA00000006203010C010100
    Wrapped command --> 84E40080144F0AA00000006203010C010156679B9711B83FAB00
    Response <-- 6A88
    delete_applet() returns 0x80206A88 (6A88: Referenced data not found.)
    install -file HelloWorld.cap -nvDataLimit 500 -instParam 00 -priv 2
    file name HelloWorld.cap
    Command --> 80E602001F09A00000006203010C0107A0000000030000000AEF08C60201A8C80201
    F40000
    Wrapped command --> 84E602002709A00000006203010C0107A0000000030000000AEF08C60201
    A8C80201F400D35F07F1D11A31E500
    Response <-- 6985
    install_for_load() returns 0x80206985 (6985: Command not allowed - Conditions of use not satisfied.)What it does mean?..
    so, can i reset THE RETRY COUNTER of my Java Card?..
    could you give me an example script that reset the Retry Counter?..
    Thanks in advance..
    Sorry i really confuse.. :(

  • Java card with javacardx.framework.math.BigNumber

    Could somebody point me to a vendor for java cards that support javacardx.framework.math.BigNumber?
    I searched this forum for 2.2.2 vendors, but could only find Athena IDProtect (http://www.athena-scs.com/product.asp?pid=32). The friendly support at Athena told me that this card does support the above package.
    Are there any other vendors of 2.2.2 cards that I could contact?

    Hi
    I am student working on a smart card project
    i am totally new to this field i have a lot of doughs to be cleared ..can you help me in this section
    my email id [email protected]
    i have return my doughs under the title : What is Client-Side API for RMI on the Java Card Platform
    : java card virtual machine

  • How to start with java card

    hello,
    i'm new to java card n know a bit of core java.. my superior of company asked me to get complete knowledge on java card.. iworked for 1 month on native cards..n know a bit of gsm 11.14. I want a favour.
    my queries:-
    a) how and from where should i start
    b) wat all basics i need to know &
    c)how to work on this card.
    ANY REPLY WILL BE APPRECIATED..
    Thanks

    a)
    - Look at Sun's tutorials on Java Card.
    - Z. Chen's book from Sun about smart cards gives you deeper knowledge about the Java Card technology.
    - Furthermore there is a great reference book about smart cards in general from W. Rankl.
    b)
    - Java: You should have basic understanding and knowledge about Java.
    - Java Card: is a subset of Java, but you need to be much more aware of the Java Card VM and RE.
    - You need to have some specifications at hand
    - Java Card API, VM and RE
    - GlobalPlatform
    - ISO 7816 and ISO 14443 for CL
    c)
    - There is a number of smart card operating systems.
    - I recommend the Java Card Open Platform (JCOP) from IBM/NXP. There is a good developer environment (JCOP Tools plugin for Eclipse) where you can start developing against a smart card SW simulator.

Maybe you are looking for

  • Not able to send instant message through CLP

    Hello All, I am a beginner in portals. I am doing a test assignment on collaboration. 1.I have enabled the Collaboration Launch Pad. 2.Now when I click on the link, CLP opens. I have added some contacts to it. 3.Then I tried to send an instant messag

  • Is there any way to delete more than one email from the iPhone at a time?

    What if I know I've read everything already online - can I press my Mail icon and instead of opening & deleting one by one, can't I delete everything in my Mail that's there? THANKS!

  • 9.3.4 update error

    i have window 7 64 bit. adobe 9.3.4. it keeps say update is ready and when i tell it to install i get these errors. error reading from file c:\users\alan\appdata\local\temp\ixp322.tmp\quicktime.msi.  verify that the file exists and that you can acces

  • No matter what I do I always get a 404Error for two of my pages

    No matter What I do I cannot link to two pages of mine every time I try I get a 404 error.. The url is the exact url I even use the thing and drag it over to the file and look at it to make sure... No matter what page I try to link to one of these tw

  • How to add partition to T400 (Vista 64-bit)?

    i just got my T400 yesterday and uninstalled all the crap, updated, and installed all my apps.  the process took several hours.  Then, I used Acronis Disk Director 10 (boot cd) to split the C: partition in two, so that I could move my documents onto