我正在开发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,