Now I try to encrypt the parameters of the cards' private key (p, q, mod p,....). And here I get the error. The export of the private key parameters to the offcard application works fine, only when I try to encrypt the parameters on the card before, I get errors. I think it fails when I try to call the encrypt function on the card.
Code: Select all
private void exportPrivateKey(APDU apdu)
{
byte[] baAPDUBuffer = apdu.getBuffer();
short sLc = (short)(baAPDUBuffer[ISO7816.OFFSET_LC] & 0x00FF);
byte P2 = (byte)(baAPDUBuffer[ISO7816.OFFSET_P2] & 0xFF);
switch (P2) {
case 0x00: // Get Prime P
baAPDUBuffer[0] = (byte)(PrivateRSAKey1024).getP(baAPDUBuffer, (short)1);
try
{
encrypt(apdu, (short)((baAPDUBuffer[0]& 0xFF) + 1));
}
catch (Exception ex)
{
ISOException.throwIt((short) 0xbbb3);
}
Code: Select all
private void encrypt(APDU apdu, short dataToEncrypt)
{
try
{
data = new byte[ (short) 0x40];
cipher.init(publicExportKey, Cipher.MODE_ENCRYPT);
short outbytes;
outbytes = cipher.doFinal(bytesValue(dataToEncrypt),(short)2, (short) 0x40, data, (short)0);
apdu.setOutgoing();
apdu.setOutgoingLength(outbytes);
apdu.sendBytesLong(data, (short)ISO7816.OFFSET_CDATA, (short)outbytes);
}
catch (Exception ex)
{
ISOException.throwIt((short) 0xbbb7);
}
}