JavacardOS will not accept order any more, please contact our partner Feitian online Store:
https://ftsafe.en.alibaba.com/index.html
https://ftsafe.en.alibaba.com/index.html
Rsa algorithom with private key
Rsa algorithom with private key
Hello sir,
can any one help me "how to set RSA ALGORITH0M WITH PRIVATE KEY" with any code or doc.
Regards,
Naresh
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
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);
}
}
}
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
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.
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.
-
- Posts: 5
- Joined: Thu Jul 19, 2018 2:30 am
- Points :84
- Contact:
Re: Rsa algorithom with private key
wow.. Good source.
Please tell me the script that runs this source.
Thank you.
Please tell me the script that runs this source.
Thank you.
Re: Rsa algorithom with private key
@naresh
What's error ? You should show me the error code.
What's error ? You should show me the error code.
Re: Rsa algorithom with private key
Can u please send me the APDU commands to this .
Re: Rsa algorithom with private key
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;
//create 1024bits key
00 00 00 80;
// set private key
00 01 00 80 74EFE44606BB20AAFE27BE66391B982EFE381C94B77D9C4FE24A28A4411CBF882A60FD8026938B3D5CD3ABDBE6FB2241101551B228EECF85118FEB7213B6C91D34C411EDC1C3153ECC9192F112B298938FF9DEE798DB89EAAF085542B840998E933637E20E6635B495FFFB3CD4D07E7F2BB6EC5400CE8F416161E692C7AAB801;
//set public key
00 02 00 80 B30222D01BF198F29F5C916998EC09270066B910069D8CD75AA3B74737481E432CB5EC7103F7F9676673011F228E7754A9619F453646E5B05B970711623D11A88A25AC33189EBD5906642AB4044D24D15524EB6ED06C6A1E91806C632D732A80A055225E21DDDCDE02678E0F33EEC5C40B81E31700ECE890C552797206F584A9;
Who is online
Users browsing this forum: Google [Bot] and 69 guests