Exception (Javacard)如何知道错误的原因?
我不明白为什么会出现SW(6300)。(objRSAKeyPair.genKeyPair();) 我正在实现密钥大小为2048位的RSA密码。 在1024位的情况下,没有问题。 但是,在2048位的情况下,卡输出SW 6300 因为我想知道确切的原因, 我实现了下面输出详细原因的异常代码Exception (Javacard)如何知道错误的原因?,exception,rsa,javacard,Exception,Rsa,Javacard,我不明白为什么会出现SW(6300)。(objRSAKeyPair.genKeyPair();) 我正在实现密钥大小为2048位的RSA密码。 在1024位的情况下,没有问题。 但是,在2048位的情况下,卡输出SW 6300 因为我想知道确切的原因, 我实现了下面输出详细原因的异常代码 private RSAPrivateCrtKey objRSAPriKey=null; private RSAPublicKey objRSAPubKey=null; pri
private RSAPrivateCrtKey objRSAPriKey=null;
private RSAPublicKey objRSAPubKey=null;
private KeyPair objRSAKeyPair=null;
private Signature objRSASign=null;
...
public static void install(byte[] bArray, short bOffset, byte bLength){
new AAA(bArray, bOffset, bLength);
}
private AAA(byte bArray[], short bOffset, byte bLength){
// Create RSA Keys and Pair
objRSAPriKey = (RSAPrivateCrtKey)KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_CRT_PRIVATE, KeyBuilder.LENGTH_RSA_2048, false);
objRSAPubKey = (RSAPublicKey)KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PUBLIC, KeyBuilder.LENGTH_RSA_2048, false);
objRSAKeyPair= new KeyPair(KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_2048);
try {
objRSAKeyPair.genKeyPair(); // [[[ Error Position ]]]
}
catch(CryptoException c)
{
short reason = c.getReason();
ISOException.throwIt(reason);
}
// Create Signature Object
objRSASign = Signature.getInstance(Signature.ALG_RSA_SHA_PKCS1, false);
register();
}
但该卡仍然输出6300,而不是原因码。
也许JCRE会输出错误6300
我不明白为什么JCRE输出SW 6300,这意味着基于GPSpec的“主机密码验证失败”。
错误代码部分正在生成RSA的密钥对,而不是身份验证
<我的问题>
我改了密码。(我的完整代码见下文) 我遵循了您的注释,因此我将代码部分移到了process()。 但它仍然输出SW 6300。 请分享您宝贵的知识和经验
package Test;
import javacard.framework.*;
import javacard.security.*;
import javacardx.crypto.*;
public class Test extends Applet{
private RSAPrivateCrtKey objRSAPriKey=null; // Object for RSA Private Key
private RSAPublicKey objRSAPubKey=null; // Object for RSA Public Key
private KeyPair objRSAKeyPair=null; // Object for RSA Key Pair
private Signature objRSASign=null; // Object for RSA Signature
public static void install(byte[] bArray, short bOffset, byte bLength){
new Test(bArray, bOffset, bLength);
}
private Test(byte bArray[], short bOffset, byte bLength){
// Create RSA Keys and Pair
objRSAPriKey = (RSAPrivateCrtKey)KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_CRT_PRIVATE, KeyBuilder.LENGTH_RSA_2048, false);
objRSAPubKey = (RSAPublicKey)KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PUBLIC, KeyBuilder.LENGTH_RSA_2048, false);
objRSAKeyPair= new KeyPair(KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_2048);
objRSASign = Signature.getInstance(Signature.ALG_RSA_SHA_PKCS1, false);
register();
}
public void process(APDU apdu){
byte buf[] = apdu.getBuffer();
try {
objRSAKeyPair.genKeyPair(); // [[[ Error Position ]]]
ISOException.throwIt((short)0x9999); // for check
}
catch(CryptoException c)
{
//this line will give you the reason of problem
short reason = c.getReason();
ISOException.throwIt(reason); // for check
}
finally
{
ISOException.throwIt((short)0x8888); // for check
}
return;
}
}
这是APDU命令/响应 1。(2048位)小程序安装阶段 2。案例2 西南:8888
public void process(APDU apdu){
byte buf[] = apdu.getBuffer();
try {
// Case 1
ISOException.throwIt((short)0x6300); // for check
ISOException.throwIt((short)0x5555); // for check
objRSAKeyPair.genKeyPair();
ISOException.throwIt((short)0x9999); // for check
}
catch(CryptoException c)
{
//this line will give you the reason of problem
short reason = c.getReason();
ISOException.throwIt(reason); // for check
}
catch(ISOException c)
{
ISOException.throwIt((short)0x6666); // for check
}
finally
{
ISOException.throwIt((short)0x8888); // for check
}
ISOException.throwIt((short)0x7777); // for check
return;
}
public void process(APDU apdu){
byte buf[] = apdu.getBuffer();
try {
// Case 2
//ISOException.throwIt((short)0x6300); // for check
ISOException.throwIt((short)0x5555); // for check
objRSAKeyPair.genKeyPair();
ISOException.throwIt((short)0x9999); // for check
}
catch(CryptoException c)
{
//this line will give you the reason of problem
short reason = c.getReason();
ISOException.throwIt(reason); // for check
}
catch(ISOException c)
{
ISOException.throwIt((short)0x6666); // for check
}
finally
{
ISOException.throwIt((short)0x8888); // for check
}
ISOException.throwIt((short)0x7777); // for check
return;
}
3。案例3
西南:6300
public void process(APDU apdu){
byte buf[] = apdu.getBuffer();
try {
// Case 3
//ISOException.throwIt((short)0x6300); // for check
//ISOException.throwIt((short)0x5555); // for check
objRSAKeyPair.genKeyPair();
ISOException.throwIt((short)0x9999); // for check
}
catch(CryptoException c)
{
//this line will give you the reason of problem
short reason = c.getReason();
ISOException.throwIt(reason); // for check
}
catch(ISOException c)
{
ISOException.throwIt((short)0x6666); // for check
}
finally
{
ISOException.throwIt((short)0x8888); // for check
}
ISOException.throwIt((short)0x7777); // for check
return;
}
请将您的代码移动到process(..)方法并尝试选择applet…,然后您将获得正确的原因代码。它在构造函数中不工作的原因可能是因为它不允许在register()之前抛出任何异常……但我不确定。小程序选择命令00 A4 04 00 XX AID XX-小程序AIDYep的长度,通常
ISOException
状态字不会由install
返回。接得好,@AnuragSharma。就我而言,也是一样的。我补充了上面的完整代码。@user2642459我怀疑6300个状态字来自外部身份验证失败,而试图访问安装小程序或卡管理器PIN验证是错误的。这意味着您的小程序尚未安装。若要进行更多调查,请同时共享您的日志。@user2642459请在评论中使用@向我推荐,以便我收到通知以帮助您更快地完成工作。谢谢:)
[ Connecting a Card in Terminal(ACS ACR122U PICC Interface 0) ]
- ATR(S) = 3B8E8001107880B0020031C0641F270100FF06
*** A Card is connected successfully
[ Card ] <== 00A4040007D4106509900090
[ Card ] ==> 8888 // finally() { ... }
public void process(APDU apdu){
byte buf[] = apdu.getBuffer();
try {
// Case 1
ISOException.throwIt((short)0x6300); // for check
ISOException.throwIt((short)0x5555); // for check
objRSAKeyPair.genKeyPair();
ISOException.throwIt((short)0x9999); // for check
}
catch(CryptoException c)
{
//this line will give you the reason of problem
short reason = c.getReason();
ISOException.throwIt(reason); // for check
}
catch(ISOException c)
{
ISOException.throwIt((short)0x6666); // for check
}
finally
{
ISOException.throwIt((short)0x8888); // for check
}
ISOException.throwIt((short)0x7777); // for check
return;
}
public void process(APDU apdu){
byte buf[] = apdu.getBuffer();
try {
// Case 2
//ISOException.throwIt((short)0x6300); // for check
ISOException.throwIt((short)0x5555); // for check
objRSAKeyPair.genKeyPair();
ISOException.throwIt((short)0x9999); // for check
}
catch(CryptoException c)
{
//this line will give you the reason of problem
short reason = c.getReason();
ISOException.throwIt(reason); // for check
}
catch(ISOException c)
{
ISOException.throwIt((short)0x6666); // for check
}
finally
{
ISOException.throwIt((short)0x8888); // for check
}
ISOException.throwIt((short)0x7777); // for check
return;
}
public void process(APDU apdu){
byte buf[] = apdu.getBuffer();
try {
// Case 3
//ISOException.throwIt((short)0x6300); // for check
//ISOException.throwIt((short)0x5555); // for check
objRSAKeyPair.genKeyPair();
ISOException.throwIt((short)0x9999); // for check
}
catch(CryptoException c)
{
//this line will give you the reason of problem
short reason = c.getReason();
ISOException.throwIt(reason); // for check
}
catch(ISOException c)
{
ISOException.throwIt((short)0x6666); // for check
}
finally
{
ISOException.throwIt((short)0x8888); // for check
}
ISOException.throwIt((short)0x7777); // for check
return;
}