Beispiel #1
0
  /**
   * Reads private key from the provided InputStream
   *
   * @param input InputStream of the private key
   * @return PGPSecretKey
   * @throws LRException NO_KEY error if the key cannot be obtained from the input stream
   */
  private PGPSecretKey readSecretKey(InputStream input) throws LRException {
    PGPSecretKeyRingCollection pgpSec;

    try {
      pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(input));
    } catch (Exception e) {
      throw new LRException(LRException.NO_KEY);
    }

    java.util.Iterator keyRingIter = pgpSec.getKeyRings();
    while (keyRingIter.hasNext()) {
      PGPSecretKeyRing keyRing = (PGPSecretKeyRing) keyRingIter.next();

      java.util.Iterator keyIter = keyRing.getSecretKeys();
      while (keyIter.hasNext()) {
        PGPSecretKey key = (PGPSecretKey) keyIter.next();

        if (key.isSigningKey()) {
          return key;
        }
      }
    }

    throw new LRException(LRException.NO_KEY);
  }