Excited to tell you that our welfare activity has been upgraded - Paying only $5.00 + Freight to get JCOP J3H145 card and A40CR card.
Please check this post for more details.

Moreover, if you want to get Free Samples by Paying Freight only , please check this page.

Rsa algorithom with private key

JavaCard Applet Development Related Questions and Answers.
naresh
Posts: 20
Joined: Fri May 11, 2018 11:29 am
Points :378
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: 40
Joined: Wed Nov 04, 2015 7:23 am
Points :286
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: 20
Joined: Fri May 11, 2018 11:29 am
Points :378
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 :80
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.

BirdKing
Posts: 40
Joined: Wed Nov 04, 2015 7:23 am
Points :286
Contact:

Re: Rsa algorithom with private key

Post by BirdKing » Thu Aug 16, 2018 9:45 pm

@naresh
What's error ? You should show me the error code.

naresh
Posts: 20
Joined: Fri May 11, 2018 11:29 am
Points :378
Contact:

Re: Rsa algorithom with private key

Post by naresh » Thu Oct 04, 2018 12:38 am

Can u please send me the APDU commands to this .

BirdKing
Posts: 40
Joined: Wed Nov 04, 2015 7:23 am
Points :286
Contact:

Re: Rsa algorithom with private key

Post by BirdKing » Fri Oct 12, 2018 3:43 am

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;

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 2 guests

JavaCard OS : Disclaimer