1 2 3 4 Previous Next 57 Replies Latest reply on Feb 13, 2011 11:55 AM by Sebastien_Lorquet Go to original post
      • 45. Re: RSA implementation basics ...
        safarmer
        Hi,

        It depends on which direction you want the encrypted data to go. If you want to send encrypted data to the card you would swap around the host and card just like you said.

        To send the public key you have a couple of options:
        1) You could have two apdu's you send to the card. One that returns the modulus and another that returns the exponent. You can convert both of these to a BigInteger in Java and use these to create the key object.
        2) You can return a DER encoded public key that contains the DER encoded ASN.1 structure of the RSA public key. This can then be used to create the public key.
        RSAPublicKey ::= SEQUENCE {
            modulus           INTEGER,  -- n
            publicExponent    INTEGER   -- e 
        }
        There are methods on the RSAPublicKey interface to extract both of these.

        Cheers,
        Shane
        • 46. Re: RSA implementation basics ...
          safarmer
          Narsee wrote:
          Also, Step #3 on how to use the public key received by host from card to encrypt the data?
          Is your host application in Java?

          Cheers,
          Shane
          • 48. Re: RSA implementation basics ...
            safarmer
            Some Java code (simple example) to encrypt some data assuming you have the modulus and exponent from the card as BigIntegers:
            RSAPublicKeySpec spec = new RSAPublicKeySpec(modulus, publicExponent);
            RSAPublicKey key = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(spec);
            Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
            cipher.init(Cipher.ENCRYPT_MODE, key);
            byte[] ciphertext = cipher.doFinal(inputData);
            Cheers,
            Shane
            • 49. Re: RSA implementation basics ...
              843851
              Shane,

              I did try out the code. The encryption seems to be working fine but decryption is failing for some reason (kind of hanging). I have opened a seperate thread with the code (RAS - problem with Decryption ...) (RAS - is a typo in the subjectline), since this is becoming too lengthy.
              Looking forward for your help.
              • 50. Re: RSA implementation basics ...
                843851
                Yes we got how to implement RSA on smart cards but i am facing problem in loading of verisign certificates on smart cards. Please suggest me steps for the loading of certificates on H31-10 smart card.
                • 51. Re: RSA implementation basics ...
                  843851
                  I have to load *.cer file and *.prv file on H31-10 smart card.
                  Please suggest me how we can load these files on smart card.
                  I am in hurry for these steps
                  Thanks in advance
                  • 52. Re: RSA implementation basics ...
                    843851
                    JCOP31v2.4.1 supports AES.
                    • 53. Re: RSA implementation basics ...
                      843851
                      smarty_card_pants wrote:
                      JCOP31v2.4.1 supports AES.
                      Even with a HW co-processor! Not like other vendors with an AES SW implementation.
                      • 54. Re: RSA implementation basics ...
                        Umer
                        can you please paste the code of host application. I realy need it.
                        Thank u...
                        • 55. Re: RSA implementation basics ...
                          796440
                          Muhammad Umer wrote:
                          can you please paste the code of host application. I realy need it.
                          Thank u...
                          1. Do not revive old threads. Start your own thread.

                          2. This is not a code service. People come here to get help with Java, and other people come here to help them. If you want someone to write code for you, go somewhere else, and pay them. Unless of course this is code that you are expected to write yourself, in which case getting somebody else to do it for you is dishonest.

                          If you want to actually learn something about Java, then start your own thread, show what you've tried, and explain clearly and precisely the specific problems you're having. Don't say things like "urgent" or "ASAP" or "I really need it." Your urgency is your problem, and nobody hear cares about it.
                          • 56. Re: RSA implementation basics ...
                            Umer
                            ok sir. I am sorry for my mistake.
                            I want to learn, thats why i am here. And thank you for directing me towards +ive direction.                                                                                                                                                                                                                                                                   
                            • 57. Re: RSA implementation basics ...
                              Sebastien_Lorquet
                              Then, use your own padding when input length is not a multiple of 8 bytes...
                              1 2 3 4 Previous Next