在卡和终端之间生成安全通道
Generate secure channel between card and terminal
我想在卡和终端之间生成安全通道。这是我的代码:
final static byte INIT_UPDATE = (byte) 0x50;
final static byte EXT_AUTHENTICATE = (byte) 0x82;
SecureChannel sc;
public void process(APDU apdu) throws ISOException {
if (selectingApplet()) {
return;
}
byte[] buffer = apdu.getBuffer();
short inlength = 0;
try
{
switch (buffer[ISO7816.OFFSET_INS]) {
case INIT_UPDATE:
case EXT_AUTHENTICATE:
makeSecureChannel(apdu);
break;
}
catch (CryptoException e)
{
short r = e.getReason();
ISOException.throwIt(r);
}
}
private void makeSecureChannel(APDU apdu)
{
byte[] buf = apdu.getBuffer();
byte cla = buf[ISO7816.OFFSET_CLA];
byte ins = buf[ISO7816.OFFSET_INS];
try
{
apdu.setIncomingAndReceive();
if(ins == INIT_UPDATE)
{
sc = GPSystem.getSecureChannel();
}
short len = sc.processSecurity(apdu);
apdu.setOutgoing();
apdu.setOutgoingLength(len);
apdu.sendBytes(ISO7816.OFFSET_CDATA, (short) len);
}
catch(APDUException ex1)
{
ISOException.throwIt(ex1.getReason());
}
}
当我发送命令 80 50 20 00 08 01 15 6A 2A F5 64 87 CF
时出现错误 6a88
,当我发送命令 00 50 20 00 08 01 15 6A 2A F5 64 87 CF
时出现错误 6e00
。
每个人都可以帮助我吗?
Statusword 6E00
不是很有趣。这意味着您发送的 CLA (class) 字节不正确。那是因为 INITIALIZE UPDATE 没有在 ISO 7816 中定义,所以它是一个专有命令。专有命令必须设置其专有位。所以class字节80
是唯一正确的。
顺便说一句,让我们关注 INIT UPDATE 的响应:6A88
。 6A88
表示 "reference data not found"。这可能意味着 P1 和 P2 引用的密钥不匹配。将 P1 和 P2 都放入 00
以确保密钥自动 selected(如果要显式 select 密钥,请检查响应数据中的 "key information" P1 中的版本)。
我想在卡和终端之间生成安全通道。这是我的代码:
final static byte INIT_UPDATE = (byte) 0x50;
final static byte EXT_AUTHENTICATE = (byte) 0x82;
SecureChannel sc;
public void process(APDU apdu) throws ISOException {
if (selectingApplet()) {
return;
}
byte[] buffer = apdu.getBuffer();
short inlength = 0;
try
{
switch (buffer[ISO7816.OFFSET_INS]) {
case INIT_UPDATE:
case EXT_AUTHENTICATE:
makeSecureChannel(apdu);
break;
}
catch (CryptoException e)
{
short r = e.getReason();
ISOException.throwIt(r);
}
}
private void makeSecureChannel(APDU apdu)
{
byte[] buf = apdu.getBuffer();
byte cla = buf[ISO7816.OFFSET_CLA];
byte ins = buf[ISO7816.OFFSET_INS];
try
{
apdu.setIncomingAndReceive();
if(ins == INIT_UPDATE)
{
sc = GPSystem.getSecureChannel();
}
short len = sc.processSecurity(apdu);
apdu.setOutgoing();
apdu.setOutgoingLength(len);
apdu.sendBytes(ISO7816.OFFSET_CDATA, (short) len);
}
catch(APDUException ex1)
{
ISOException.throwIt(ex1.getReason());
}
}
当我发送命令 80 50 20 00 08 01 15 6A 2A F5 64 87 CF
时出现错误 6a88
,当我发送命令 00 50 20 00 08 01 15 6A 2A F5 64 87 CF
时出现错误 6e00
。
每个人都可以帮助我吗?
Statusword 6E00
不是很有趣。这意味着您发送的 CLA (class) 字节不正确。那是因为 INITIALIZE UPDATE 没有在 ISO 7816 中定义,所以它是一个专有命令。专有命令必须设置其专有位。所以class字节80
是唯一正确的。
顺便说一句,让我们关注 INIT UPDATE 的响应:6A88
。 6A88
表示 "reference data not found"。这可能意味着 P1 和 P2 引用的密钥不匹配。将 P1 和 P2 都放入 00
以确保密钥自动 selected(如果要显式 select 密钥,请检查响应数据中的 "key information" P1 中的版本)。