Hi all,
I'm currently trying to send an RSA Public Key generated off the card, to the card!
I have the following parameters to send:
RSA public modulus= 009c0a9763b9775a70e1b84069c862407af3d5ce4489d81307cb2a7931050e1d265b13fc0f37c07d0be54b8e335cccec19bd13e54e8407984a501b4b5789e672b3
RSA public exponent = 010001
I'm doing an APDU Exchange and the card code to receive the commands is the next:
if(buf[ISO7816.OFFSET_INS] == SET_PUBLIC_KEY){
//Check if Parameter P2 Contains supported request for Public Key
byte keyElement = (byte)(buf[ISO7816.OFFSET_P2] & 0xFF);
if((keyElement != 0x00) && (keyElement != 0x01))
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
else{
//keyElement = 0 is set for Modulus
if(keyElement == 0){
short numBytes = apdu.setIncomingAndReceive();
Util.arrayCopy(buf, ISO7816.OFFSET_CDATA, tempBuffer, (short)0, numBytes);
rsa_PublicKey.clearKey();
rsa_PublicKey.setModulus(buf, ISO7816.OFFSET_CDATA,numBytes);
}
//Set for exponent
else if(keyElement == 1){
short numBytes = apdu.setIncomingAndReceive();
Util.arrayCopy(buf, ISO7816.OFFSET_CDATA, tempBuffer, (short)0, numBytes);
rsa_PublicKey.setExponent(buf, ISO7816.OFFSET_CDATA, numBytes);
}
}
}
Apparently the card accepts the APDU commands i send:
B0 21 00 00 key - For Modulus
B0 21 00 01 key - For Exponent
But after this when i try to encrypt something nothing happens... I think the problem may be in the way i am setting the public key exponent and modulus.
So it is a good practice to use the setExponent and setModulus to set the key parameters and use the key after that? Or is there something missing in my approach?
Thanks in advance.
Cheers,
Rodrigo