Page 1 of 1
Rsa algorithom with private key
Posted: Thu Jul 05, 2018 4:14 am
by naresh
Hello sir,
can any one help me "how to set RSA ALGORITH0M WITH PRIVATE KEY" with any code or doc.
Regards,
Naresh
Re: Rsa algorithom with private key
Posted: Fri Jul 06, 2018 1:34 am
by BirdKing
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);
}
}
}
Re: Rsa algorithom with private key
Posted: Fri Aug 10, 2018 2:18 am
by naresh
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.
Re: Rsa algorithom with private key
Posted: Mon Aug 13, 2018 4:04 am
by dongho1492
wow.. Good source.
Please tell me the script that runs this source.
Thank you.
Re: Rsa algorithom with private key
Posted: Thu Aug 16, 2018 9:45 pm
by BirdKing
@naresh
What's error ? You should show me the error code.
Re: Rsa algorithom with private key
Posted: Thu Oct 04, 2018 12:38 am
by naresh
Can u please send me the APDU commands to this .
Re: Rsa algorithom with private key
Posted: Fri Oct 12, 2018 3:43 am
by BirdKing
for 1024bits example:
//create 1024bits key
00 00 00 80;
// set private key
00 01 00 80 74EFE44606BB20AAFE27BE66391B982EFE381C94B77D9C4FE24A28A4411CBF882A60FD8026938B3D5CD3ABDBE6FB2241101551B228EECF85118FEB7213B6C91D34C411EDC1C3153ECC9192F112B298938FF9DEE798DB89EAAF085542B840998E933637E20E6635B495FFFB3CD4D07E7F2BB6EC5400CE8F416161E692C7AAB801;
//set public key
00 02 00 80 B30222D01BF198F29F5C916998EC09270066B910069D8CD75AA3B74737481E432CB5EC7103F7F9676673011F228E7754A9619F453646E5B05B970711623D11A88A25AC33189EBD5906642AB4044D24D15524EB6ED06C6A1E91806C632D732A80A055225E21DDDCDE02678E0F33EEC5C40B81E31700ECE890C552797206F584A9;