Example #1
0
  private cardTest() {

    // Instantiate all object the applet will ever need
    // pin= new OwnerPIN(MAX_LENGTH, MAX_ATTEMPTS);
    // if(bArray==null){//check
    //			If no pin is passed as parameter at installation time use default 0000
    // pin.update(new byte[] {0x00,0x00,0x00,0x00}, (short) 0, (byte) 0x04);
    //	}
    // else {
    // pin.update(bArray, bOffset,  bLength);
    // }

    try {
      // Set signature algorithm
      sig = Signature.getInstance(Signature.ALG_RSA_SHA_PKCS1, false);
      // Generate the card keys
      keys.genKeyPair();
      // Get the public key
      k = (RSAPublicKey) keys.getPublic();
      // Get the private key
      k2 = (RSAPrivateKey) keys.getPrivate();
      // Initialize the signature object with card private key
      sig.init(k2, Signature.MODE_SIGN);
    } catch (CryptoException ex) {
      ISOException.throwIt((short) (ex.getReason()));
    } catch (SecurityException ex) {
      ISOException.throwIt((short) (0x6F10));
    } catch (Exception ex) {
      ISOException.throwIt((short) (0x6F20));
    }
  }