It's our great honour to announce the Industry’s First VHBR CCID reader - VHBR Dual interface smart card reader vR504. It is able to support the world’s fastest ePassports.

To celebrate the new product release, there is Special Discount for New Registered Members in our store.
- Get $20.00 OFF instantly for smart card reader vR504, R502 and bR301

Come to get the readers now!

Rsa algorithom with private key

JavaCard Applet Development Related Questions and Answers.
naresh
Posts: 13
Joined: Fri May 11, 2018 11:29 am
Points: 264
Contact:

Rsa algorithom with private key

Postby naresh » Thu Jul 05, 2018 4:14 am

Hello sir,
can any one help me "how to set RSA ALGORITH0M WITH PRIVATE KEY" with any code or doc.
Regards,
Naresh

BirdKing
Posts: 31
Joined: Wed Nov 04, 2015 7:23 am
Points: 206
Contact:

Re: Rsa algorithom with private key

Postby BirdKing » Fri Jul 06, 2018 1:34 am

so easy.


package com.ftsafe.javacard.test;

import javacard.framework.*;
import javacard.security.*;
import javacardx.crypto.*;

public class testKey extends Applet
{
final short MAX_RSA = (short)256;

final byte INS_CREATE_KEY = (byte)0x00;
final byte INS_SET_KEY_D = (byte)0x01;
final byte INS_SET_KEY_N = (byte)0x02;

RSAPrivateKey rsaPrivKey;
short len;
byte[] tempBuf;
short tempOffset;

public testKey()
{
tempBuf = JCSystem.makeTransientByteArray(MAX_RSA, JCSystem.CLEAR_ON_DESELECT);
tempOffset = 0;
}

public static void install(byte[] bArray, short bOffset, byte bLength)
{
new testKey().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
}

public void process(APDU apdu)
{
if (selectingApplet())
{
return;
}

byte[] buf = apdu.getBuffer();
switch (buf[ISO7816.OFFSET_INS])
{
case INS_CREATE_KEY:
len = Util.makeShort(buf[ISO7816.OFFSET_P1], buf[ISO7816.OFFSET_P2]);
rsaPrivKey = (RSAPrivateKey)KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PRIVATE, len, false);
break;
case INS_SET_KEY_D:
len = (short)(((short)buf[ISO7816.OFFSET_LC]) & (short)0x00FF);

Util.arrayCopy(buf, ISO7816.OFFSET_CDATA, tempBuf, tempOffset, len);
tempOffset += len;

if (buf[ISO7816.OFFSET_P1] == (byte)0x01)
{
try
{
rsaPrivKey.setExponent(tempBuf, (short)0, tempOffset);
tempOffset = (short)0;
}
catch(CryptoException e)
{
ISOException.throwIt((short)(0x6900 | e.getReason()));
}
}
else if (buf[ISO7816.OFFSET_P1] == (byte)0x00)
{}
break;
case INS_SET_KEY_N:
len = (short)(((short)buf[ISO7816.OFFSET_LC]) & (short)0x00FF);

Util.arrayCopy(buf, ISO7816.OFFSET_CDATA, tempBuf, tempOffset, len);
tempOffset += len;

if (buf[ISO7816.OFFSET_P1] == (byte)0x01)
{
try
{
rsaPrivKey.setModulus(tempBuf, (short)0, tempOffset);
tempOffset = (short)0;
}
catch(CryptoException e)
{
ISOException.throwIt((short)(0x6900 | e.getReason()));
}
}
else if (buf[ISO7816.OFFSET_P1] == (byte)0x00)
{}
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}

}


Return to “Questions & Answers”

Who is online

Users browsing this forum: No registered users and 1 guest

JavaCard OS : Disclaimer