9 Replies Latest reply on Mar 1, 2012 10:59 PM by safarmer

    RSA key problem

      I work on a authentication project and I have a weird bug. (It's my first project on JavaCards).

      The problem is that i can't do RSA key with a lenght different than 512 bit. I load the application on an emulated card. Here's the code

      keym = new KeyManager((short)1024);
      }catch(Exception e){}

      public RSAKey(short size) throws Exception{

           bufferA = new byte[size];
           bufferB = new byte[size];

      paireDeClef = new KeyPair(KeyPair.ALG_RSA,KeyBuilder.LENGTH_RSA_1024);

      publicKey = (RSAPublicKey)paireDeClef.getPublic();
      privateKey = (RSAPrivateKey)paireDeClef.getPrivate();

      cip = Cipher.getInstance(Cipher.ALG_RSA_PKCS1,false);

      I already tried to throw a CryptoException... it didn't show me any error message.
      Am I using the try catch correctly?

      All my thanks!
        • 1. Re: RSA key problem
          No you aren't. You are catching the exception and not even printing it out. So you have no clue why it isn't working.

          Never do that.

          Print the stack trace and post it here if it still doesn't enlighten you.
          • 2. Re: RSA key problem
            What crypto algorithms are supported by your simulator?

            1 person found this helpful
            • 3. Re: RSA key problem
              It's the netbeans JCDK 3.0.2 connected


              Added 4096 bit RSA key - #6593240
              Added support for transient RSA, EC and DSA private keys - #6270329

              Got that on http://www.oracle.com/technetwork/java/javacard/releasenotes-jsp-137685.html

              Is the virtual card platform provided with it does not support those keys?
              • 4. Re: RSA key problem
                I've looked to the CryptoException...

                TheSw = 3

                and STATIC NO_SUCH_ALGORITHM = 3

                would that mean that there is no RSA algorithm other than 512 bit supported by the emulator?

                I guess I'll have to wait on the real card to make bigger keys if that's correct.
                • 5. Re: RSA key problem
                  Try using KeyPair.ALG_RSA_CRT instead of KeyPair.ALG_RSA.

                  Also, the private key may have to be an RSA CRT Private key, not just an RSA Private key. Just a thought.

                  1 person found this helpful
                  • 6. Re: RSA key problem
                    Nice try but didn't work. Still have the same error, Key_not_supported.

                    Thank you for your help!
                    • 7. Re: RSA key problem
                      I'll just wait to get the real card and see if i still have the same problem.
                      I think it's the virtual environment that makes that mistake... I'll let you know if it works with the card when I receive it.
                      • 8. Re: RSA key problem
                        What you have to do is just share a complete code(as an example) so that we can test it and let you know what is the problem. And from your code i assume that your code is the part of the applet not the host app, if not please mention. As in case of applet you can send back the reason in the catch clause but can't print the whole stack trace.
                        • 9. Re: RSA key problem

                          CREF has some documented limitations (check the developer guide that is in the JCDK). Due to export restrictions, the crypto support is quite limited. You will only be able to use 512 bit keys with CREF. You will need to use a real card or a better emulator (from a card vendor) for this.