Having trouble with using crypto in JC 2.2.2

Hi,
I am using the sourceforge Eclipse plugin for my project. Eclipse version is 3.5.
My JC version is 2.2.2. When i debug my code (Using the debug mode) the program terminates at
keypair = new KeyPair(KeyPair.ALG_RSA_CRT, (short)1024);
In the debug window (Variables) I get the cause and theSW as (0, 3) which i think implies CryptoException - NoSuchAlgorithm.
I don't understand why this shows.
It does not generate any stacktrace and shows stacktrace as null.
My code:
package test;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.security.*;
//import javacardx.crypto.*;
public class Test extends Applet {
// Private Objects
private static Key privateKey;
public static Key publicKey;
private static KeyPair keyPair;
// Private Debug objects
private byte flag = 0;
//standard APDU input offset values
public final static byte THIS_CLA = (byte)0x90;
// This is the INS for starting to generate 1024 bit RSA keys
public final static byte  GENERATE_RSA_KEYS = (byte)0x20;
// INS to sign provided hash
public final static byte  COMPLETE_TRANSACTION= (byte)0x22;
// INS to return Status of Applet.
public final static byte  INITIALIZE_UPDATE= (byte)0x24;
// INS to reset keys
public final static byte  COMPLETE_UPDATE= (byte)0x26;
// dummy byte sequences returned by this applet
private final static byte[] INIT_SEQUENCE = { (byte)0xff, (byte)0x2 };
private final static byte[] COMPLETE_SEQUENCE = { (byte)0x1, (byte)0x3 };
private final static byte[] INIT_UPDATE_SEQUENCE = { (byte)0x1, (byte)0x2, (byte)0x3 };
private final static byte[] COMPLETE_UPDATE_SEQUENCE = { (byte)0x1, (byte)0x1 };
* Constructor.
* Only this class's install method can create the applet object.
private Test() {
//perform some initialization here
register();//register this instance
* Installs this applet.
* @param byteArray the array containing installation parameters
* @param offset the starting offset in byteArray
* @param length the length in bytes of the parameter data in byteArray
public static void install(byte[] byteArray, short offset, byte length) {
new Test();
* Implementation  of the standard method for processing an incoming APDU.
* @param apdu the incoming APDU
* @exception ISOException with ISO 7816-4 response bytes
public void process(APDU apdu) {
byte buffer[] = apdu.getBuffer();
//@SuppressWarnings("unused")
flag = 0;
if (buffer[ISO7816.OFFSET_CLA] == THIS_CLA) {
switch (buffer[ISO7816.OFFSET_INS])    {
case GENERATE_RSA_KEYS:
//writeBack(apdu, INIT_SEQUENCE);
generateRSAKeys(apdu, INIT_SEQUENCE);
flag = 1;
break;
case COMPLETE_TRANSACTION:
writeBack(apdu, COMPLETE_SEQUENCE);
break;
case INITIALIZE_UPDATE:
writeBack(apdu, INIT_UPDATE_SEQUENCE);
break;
case COMPLETE_UPDATE:
writeBack(apdu, COMPLETE_UPDATE_SEQUENCE);
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
* An example method that writes back a given byte array through the apdu.
protected void generateRSAKeys(APDU apdu, byte[] bytes)  {
//byte buffer[] = apdu.getBuffer();
try {
byte[] apduBuffer = apdu.getBuffer();
// Debug flag
flag = 9;
//privateKey = KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PRIVATE,KeyBuilder.LENGTH_RSA_2048, false);
//privateKey = KeyBuilder.buildKey(KeyBuilder.TYPE_DSA_PRIVATE,KeyBuilder.LENGTH_DES, false);
//publicKey = KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PUBLIC,KeyBuilder.LENGTH_RSA_2048, false);
// Debug flag
flag = 10;   
keyPair = new KeyPair(KeyPair.ALG_RSA_CRT, (short)1024);
//keyPair = new KeyPair(KeyPair.ALG_RSA, (short)publicKey.getSize());
keyPair.genKeyPair();
publicKey = keyPair.getPublic();
// Debug flag
flag++;   
((RSAPublicKey)publicKey).getModulus(apduBuffer, (short)0);
//    apdu.setOutgoing(); // set transmission to outgoing data
//    apdu.setOutgoingLength((short) apduBuffer.length);
apdu.setOutgoingAndSend((short) 0,  (short) (publicKey.getSize()/8));
// Debug flag
flag++;       
} catch(Exception e) {
flag = 0;
* An example method that writes back a given byte array through the apdu.
protected void writeBack(APDU apdu, byte[] bytes) {
byte buffer[] = apdu.getBuffer();
// copy bytes into buffer
buffer[0] = bytes[0];
buffer[1] = bytes[1];
// set apdu for data output
apdu.setOutgoing();
apdu.setOutgoingLength( (short) (2) );
// output header
apdu.sendBytes( (short)0, (short) 2);
// writes data
//apdu.sendBytesLong( bytes, (short) 0, (short) 0 );
} NOTE: Part of the code is from an online tutorial that i found.
Thanks for your help.

Hi,
That exception generally means that the platform you are running on does not support that crypto operation. This can be an indecator that the cipher you would use this key with is not available or the key size you are using is not supported.
I am not familiar with the Eclipse plugin you mentioned, but if you are using the Java implementation of the Java Card simulator (jcwde) provided with the JCDK, ti will not support crypto operations. There have been several posts on this topic recently that you may be able to search for that will give you more details about this.
On a coding note, you should not be using the new keyword outside of the applet constructor. In fact you should not be allocating new memory outside of this constructor. This is because you should not rely on garbage collection in Java Card as it is not be implemented on all cards. If it is available on a card it may be rather slow.
Cheers,
Shane
Edited by: safarmer on 27/10/2009 17:19

Similar Messages

  • I'm having trouble with using Calculated-User Can Override, it will not honor my overide

    I'm having trouble with using Calculated-User Can Override, it will not honor my overide.  I'm using LiveCycle Designer ES v.8.2

    Reset the device:
    Press and hold the Sleep/Wake button and the Home button together for at least ten seconds, until the Apple logo appears.
    If that doesn't help, tap Settings > General > Reset > Reset All Settings
    No data is lost due to a reset.

  • Having trouble with using variables in functions and after functions..

    Morning,
    I have simplified this, as it represents the core of what’s I obviously don't know how to do. 
    Problem:
    Say I populate that variable by reading in a list if IP addresses from file, finding the line that matches the hostname and place that string into the $IPAddress variable for use later throughout the script.   I did not run into a significant problem
    until I decided to convert the routine of looking up the IP address and populating the variable into a function.   As soon as I made it a function, and called that function, the $IPAddress variable only had the data in it until the function completed. 
    Once the function had done its work, and had placed the data into the variable, I expected that “new” data to be available after the function had completed..in that variable.  But it’s like the $IPAddress variable in the main script is a totally
    different data then the variable with the same name that’s used within the function. 
    So I think this demonstrates some of what’s kicking my butt.. 
    $IPAddress = "This is the wrong data”
    Function TestFunction () 
    $IPAddress  #call to display the contents of the variable at the start of the function. 
    $IPAddress = Read-Host -Prompt "Please enter the text ‘Goober’" 
    $IPAddress   #call to display the contents of the variable at the end of the function. 
    TestFunction
    $IPAddress ​
    The output I get is: 
    This is the wrong data
    "Please enter ‘Goober’"  : where I enter Goober
    Goober
    This is the wrong data
    Huh? 
    I had expected:
    This is the wrong data
    "Please enter ‘Goober’"  : where I enter Goober
    Goober
    Goober
    What good is the repeatability of a function if it’s output is lost? 

    THis seems to work.. IS there any reason NOT to do this?
    $Global:IPAddress= "This is the wrong data” #"
    Function TestFunction{
        Write-Host $IPAddress-fore green
          $host.ui.RawUI.FlushInputBuffer()
         $Global:IPAddress =
    Read-Host -Prompt
    "Please enter the text ‘Goober’"
        return$Global:IPAddress
    TestFunction
    return$Global:IPAddress

  • I'm having trouble with something that redirects Google search results when I use Firefox on my PC. It's called the 'going on earth' virus. Do you have a fix that could rectify the vulnerability in your software?

    I'm having trouble with a virus or something which affects Google search results when I use Firefox on my PC ...
    When I search a topic gives me pages of links as normal, but when I click on a link, the page is hijacked to a site called 'www.goingonearth.com' ...
    I've done a separate search and found that other users are affected, but there doesn't seem to be a clear-cut solution ... (Norton, McAfee and Kaspersky don't seem to be able to detect/fix it).
    I'd like to continue using the Firefox/Google combination (nb: the hijack virus also affects IE but not Safari) - do you have a patch/fix that could rectify the vulnerability in your software?
    thanks

    ''' "... vulnerability in your software?" ''' <br />
    And it affects IE, too? Ya probably picked up some malware and you blame it on Firefox.
    Install, update, and run these programs in this order. They are listed in order of efficacy.<br />'''''(Not all programs detect the same Malware, so you may need to run them all to solve your problem.)''''' <br />These programs are all free for personal use, but some have limited functionality in the "free mode" - but those are features you really don't need to find and remove the problem that you have.<br />
    ''Note: If your Malware infection is bad enough and you are mis-directed to URL's other than what is posted, you may have to use a different PC to download these programs and use a USB stick to transfer them to the afflicted PC.''
    Malwarebytes' Anti-Malware - [http://www.malwarebytes.org/mbam.php] <br />
    SuperAntispyware - [http://www.superantispyware.com/] <br />
    AdAware - [http://www.lavasoftusa.com/software/adaware/] <br />
    Spybot Search & Destroy - [http://www.safer-networking.org/en/index.html] <br />
    Windows Defender: Home Page - [http://www.microsoft.com/windows/products/winfamily/defender/default.mspx]<br />
    Also, if you have a search engine re-direct problem, see this:<br />
    http://deletemalware.blogspot.com/2010/02/remove-google-redirect-virus.html
    If these don't find it or can't clear it, post in one of these forums for specialized malware removal help: <br />
    [http://www.spywarewarrior.com/index.php] <br />
    [http://forum.aumha.org/] <br />
    [http://www.spywareinfoforum.com/] <br />
    [http://bleepingcomputer.com]

  • I have been having trouble with my iphone 4 for the past day . i tried to update it to 7.0.4 then the screen went blank and it keeps telling me to connect to itunes . I have connected it to 2 computers , using different cords

    I have been having trouble with my iphone 4 for the past day . i tried to update it to 7.0.4 then the screen went blank and it keeps telling me to connect to itunes . I have connected it to 2 computers , using different cords and it doesnt recognize it . It says it is in recovery mode and i need to restore . after clicking restore it says that my iphone cannot be restored . I am very frustrated because i have been online searching for solutions all day and nothing seems to work . As soon as i turn on my phone it goes to the apple logo for about 2 seconds then the connect to itunes screen . SOMEBODY PLEASE HELP ! my phone is my life and i need it back on .

    Connect the device to iTunes and restore from the most current backup.
    If the issue continues, restore as new.

  • I'm using Adobe Photoshop CS5 Extended and am having trouble with it.

    I just reinstalled Photoshop CS5 Extended from my original disk because I was having trouble with it. I did do an uninstall before installing. Every time I quit Photoshop I get this message: "Could not save Preferences because the file is locked or you do not have the necessary access privileges. Use the ‘Get Info’ command in the Finder to unlock the file or change permissions on the file or enclosing folders." Can you tell me what to do to fix this? I went to get info and made changes to read and write, but it made no difference. Thanks for your help.
    Richard

    Some folders are hidden in the Finder. Use the "Go to Folder" command for that.
    Go menu > Go to Folder, enter:
    /Users/YOURUSERNAME/Library/Preferences/Adobe Photoshop CS5 Settings
    Gene

  • Several of us have a iPhone 6s and are having trouble with hearing and speaking at the same time when using the phone. ? The speakers seem to be too far apart? Are others having this issue? Solutions?

    Several of us have a iPhone 6plus and are having trouble with hearing and speaking at the same time when using the phone. ? The speakers seem to be too far apart? Are others having this issue? Solutions?

    Not having the problem, don't personally know anyone who is.

  • I am having trouble with my iPad, i can start it, but the iPad does not work. i tried to use the power and home button at the same time, the apple logo appears, but the iPad does not work. What am I suppose to do?

    I am having trouble with my iPad, i can start it, but the iPad does not work. i tried to use the power and home button at the same time, the apple logo appears, but the iPad does not work. What am I suppose to do?

    After the Apple logo appears, what happens then? Can you hear any sounds or if you tap on the screen, does it seem like apps can open or are you just seeing a black screen? You might have a hardware problem, but you can try restoring the software and see what happens.
    Read this in its entirety before you do anything. Make sure you read the sections at the end about using recovery mode.
    iTunes: Restoring iOS software - Support - Apple

  • Is anyone having trouble with their RAZR not ringing or only ringing sometimes? I also lose the use of any voice technology when this happens.

    Is anyone having trouble with their RAZR not ringing or only ringing sometimes? I also lose the use of any voice technology when this happens.

    What is going on with the motorola software fix?
    Tav Gauss CEO, President
    The Action Group, Human Resources Solutions
    252-237-3717
    1800-529-8470
    <http://www.theactiongrouphr.com/> www.theactiongrouphr.com
    PO Box 158
    Wilson North Carolina 27894-0158
    Follow The Action Group HR. Connect with us on  <http://capstr.at/Hd> Twitter |  <http://capstr.at/HY> LinkedIn |  <http://capstr.at/Hc> YouTube

  • I am having trouble with face time , it was working well yesterday and today am not able to use it due to an error that won't let me log in !!!

    I am having trouble with face time , it was working well yesterday and today am not able to use it due to an error that won't let me log in !!!

    I have the same exact issue. There is number of these post, but still not an answer. hope someone post an answer soon

  • I'm having trouble with the folder "Automatically add" function. She opens a folder "not added". My machine is a Vaio with Windows 7 home basic antivirus using Microsoft. Regards.

    I'm having trouble with the folder "Automatically add" function. She opens a folder "not added". My machine is a Vaio with Windows 7 home basic antivirus using Microsoft. Regards.

    Its a 64 bits.

  • Okay. I don't know if it's the broadband that I'm using or is it firefox, but I'm having trouble with a certain website namely Tumblr.

    Okay. I don't know if it's the broadband that I'm using or is it firefox, but I'm having trouble with a certain website namely Tumblr. I can login just fine, but everytime it tries to redirect me to its dashboard, it'll direct me to another site instead. I really am not sure if it's firefox or is it my internet broadband is the problem. HELP ME. I NEED TO REBLOG SOMETHING OFF TUMBLR SOOO BAD!

    No problem just happy you got it working again
    Happy Days

  • I am having trouble with my JAVA Applet. It isn't functioning on SAFARI.    It seems to have stopped working and I used it on SAFARI last year. Any suggestions ?

    I am having trouble with my JAVA Applet. It isn't functioning on SAFARI.    It seems to have stopped working and I used it on SAFARI last year. Any suggestions?

    Post in the Safari forum area.

  • I am having trouble with comcast e mail using safari

    I am having trouble with xfinity e mail using browser, SAFARI

    I too had this issue. I was recently an employee and user of Comcast and they do not support Safari. Some functions work, many don't. I used Firefox and had no issues. I also set up my mail using MAC MAIL and didn't have any issues with that.

  • Have installed Mountian Lion, now having trouble with my printer.. Printer is Canon LBP6000.. Does anyone have a driver I can use??

    Have installed Mountian Lion, now having trouble with my printer.. Printer is Canon LBP6000.. Does anyone have a driver I can use??

    It looks like this page from Canon's website will take care of you (provide drivers, etc.):
    http://www.usa.canon.com/cusa/consumer/products/printers_multifunction/laser_pri nters/imageclass_lbp6000#DriversAndSoftware

Maybe you are looking for

  • Need Help-How Store the input parameter through java bean

    Hello Sir, I have a simple Issue but It is not resolve by me i.e input parameter are not store in Ms-Access. I store the input parameter through Standard Action <jsp:useBean>. jsp:useBean call a property IssueData. this property exist in SimpleBean w

  • Complex content conversion File sender

    RecordSet     >Header   1..1          hfield1 1..1          hfield2 1..1     >/Header     >Detail      1..n          Dfield1 1..1          Dfield2 1..1          > SubDetail 1..1                  SDfield3  1..n          > /SubDetail      >/Detail /Rec

  • Exchange 2013 SP1 On-prem - Disable Outlook Anonymous NTLM?

    I'm aware there is a Group Policy admin template available to force Outlook to request only NTLM or basic authentication, however, I'd like to disable Outlook Anonymous NTLM on the server side in our Exchange 2013 SP1 on-premises installation. Is the

  • Function to be inserted into dba_source

    Hello Gurus, I have to update an existing function which is in dba_source how do I go about doing it. Please let me know Shiva

  • Problems with coverage and signal in other countryw

    Hi, I am out of my country, I am traveling, and I have problems with coverage, the signal is not stable it come and go. I have a Europe plan active with my operador, and with my previous Arc S, I dont have this problem. Any solution ? Other people wi