1
我正在開發JavaCard小程序。小程序生成RSA公鑰和在構造和使用APDU命令加密一些字節數組私鑰:JavaCard小程序不能使用RSA加密
public RSATestApplet() {
keyPair = new KeyPair(KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_2048);
keyPair.genKeyPair();
rsaPrivateKey = (RSAPrivateKey) keyPair.getPrivate();
rsaPublicKey = (RSAPublicKey) keyPair.getPublic();
cipher = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false);
register();
}
而且主要方法是:
private void encryptData(APDU apdu) {
if (!rsaPublicKey.isInitialized()) {
ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
}
byte[] apduBuffer = apdu.getBuffer();
apdu.setIncomingAndReceive();
cipher.init(rsaPrivateKey, Cipher.MODE_ENCRYPT);
byte[] encryptedBuffer = new byte[apduBuffer.length];
Util.arrayFillNonAtomic(encryptedBuffer, (short) 0,
(short) encryptedBuffer.length, (byte) 0xAA);
cipher.doFinal(encryptedBuffer, (short) 0, (short) encryptedBuffer.length, apduBuffer, (short) 0);
// Just for testing send 120 bytes
apdu.setOutgoingAndSend((short) 0, (short) 120);
}
當我嘗試安裝小程序APDU響應是6E00(其意味着:沒有精確的診斷)。
我認爲cipher.doFinal()執行時可能會出現問題。
我試着與其他小程序,一切工作正常。
我編譯我的小應用程序與JavaCard的2.2.1和Java 1.2
你有任何想法,這是怎麼回事?
您好!感謝您提供有用的建議。我已經發現原因是我的卡不支持RSA_2048。但在文檔RSA_2048支持DDA而不是SDA。事情是我不知道什麼是DDA和SDA以及如何在此模式下安裝applet。我會問問我 – raiym
http://stackoverflow.com/questions/33015169/differents-between-sda-and-dda-in-javacard – raiym