Esempio n. 1
0
 /**
  * Retrieve a DG file from the passport.
  *
  * @param dgTag Tag of the DG file to retrieve.
  * @return The bytes of the DG file.
  * @throws CardServiceException Gets thrown when there's a problem communicating with the
  *     passport.
  * @throws IOException Gets thrown when there's a problem reading the file from the passport.
  */
 public byte[] getDG(int dgTag) throws CardServiceException, IOException {
   if (activateTerminal()) {
     short dgFID = PassportFile.lookupFIDByTag(dgTag);
     CardFileInputStream dgStream = _activePassportService.readFile(dgFID);
     byte[] data = new byte[dgStream.getFileLength()];
     int read = dgStream.read(data, 0, data.length);
     if (read == data.length) return data;
   }
   return new byte[0];
 }
Esempio n. 2
0
 /**
  * Let the passport sign a message using the passports own private key.
  *
  * @param message The message to sign (can be any size)
  * @return A signature, the response from the passport.
  * @throws CardServiceException Gets thrown when there's a problem communicating with the
  *     passport.
  * @throws NoSuchAlgorithmException Gets thrown when there's no SHA1 provider present.
  */
 public byte[] signWithAA(byte[] message) throws CardServiceException, NoSuchAlgorithmException {
   if (activateTerminal()) {
     DG15File dg15 = new DG15File(_activePassportService.readFile(PassportService.EF_DG15));
     PublicKey publicKey = dg15.getPublicKey();
     MessageDigest digest = MessageDigest.getInstance("SHA1");
     byte[] digestedMessage = digest.digest(message);
     byte[] m2 = new byte[8];
     System.arraycopy(digestedMessage, 0, m2, 0, m2.length);
     return _activePassportService.sendAA(publicKey, m2);
   }
   return new byte[0];
 }