I am working on some new requirement where RSA key pair (1024) will be generated at server and Private key needs to be stored in applet which can be used fr further crypto operation.
As per my understanding to create a PrivateKey in applet i need to set the exponent and modulus for Private key but I am not clear abt how to send required private key data to the applet.
Can any body help me out in storing the Private Key into applet.
I don't think this is a good idea. RSA is designed in such a way that private key will never leave the place where it is created
Try another solution with a better security rather than to communicate RSA private key to smartcard
I've never done any requirement like yours but naively, you can do this:
- prepare an APDU carrying the private key (two components, you can configure this with P1 and P2 parameters).
- On the arrival of these APDU, try to create an RSAPrivateKey object and set the two components of it. The code snippet would be like this:
short offset = 0 ; short keySizeInBytes = 64; short keySizeInBits = 512; RSAPrivateKey privKey = (RSAPrivateKey) KeyBuilder.buildKey (KeyBuilder.TYPE_RSA_PRIVATE, keySizeInBits, false); privKey.setExponent(privExponent, offset, keySizeInBytes) ; privKey.setModulus (privModulus, offset, keySizeInBytes) ;
I think the way to send the Private Key data (modulus and exponent) depends on the implementation of the server & your applet. Communication between server and the applet can be done by 03.48 SMS. The spec of the 03.48 SMS already defined the securty inside the SMS message, which is the modulus & exponent. I think you need to define the SMS message structure which is recognized by Server & Applet.
For storing the key inside the applet, you can use the standard class for Private Key which is provided by Java Card API.
Hope this answer is helpful