In order to thank you for all members' support of our website, we are holding new events - Getting Free Samples by Paying Freight only.
Want to get free samples? Please check this post for more details.

Rsa algorithom with private key

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

Rsa algorithom with private key

Post by 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: 32
Joined: Wed Nov 04, 2015 7:23 am
Points :218
Contact:

Re: Rsa algorithom with private key

Post by 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);
}
}

}

naresh
Posts: 16
Joined: Fri May 11, 2018 11:29 am
Points :308
Contact:

Re: Rsa algorithom with private key

Post by naresh » Fri Aug 10, 2018 2:18 am

Hello sir,
When i run this code
rsaPrivKey = (RSAPrivateKey)KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PRIVATE, len, false);
inbuilt lines are throwing error what should i do for this..?

Thanks and Regards,
Thammineni Naresh.

dongho1492
Posts: 5
Joined: Thu Jul 19, 2018 2:30 am
Points :72
Contact:

Re: Rsa algorithom with private key

Post by dongho1492 » Mon Aug 13, 2018 4:04 am

wow.. Good source.

Please tell me the script that runs this source.

Thank you.

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 3 guests

JavaCard OS : Disclaimer