Skip to content

Instantly share code, notes, and snippets.

@jordanbaucke
Created July 26, 2014 14:27
Show Gist options
  • Save jordanbaucke/0a677057cc95cfe77be4 to your computer and use it in GitHub Desktop.
Save jordanbaucke/0a677057cc95cfe77be4 to your computer and use it in GitHub Desktop.
public static PGPSecretKey readSecretKey(InputStream input) throws IOException, PGPException {
PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(
PGPUtil.getDecoderStream(input));
Iterator keyRingIter = pgpSec.getKeyRings();
while (keyRingIter.hasNext()) {
PGPSecretKeyRing keyRing = (PGPSecretKeyRing) keyRingIter.next();
Iterator keyIter = keyRing.getSecretKeys();
while (keyIter.hasNext()) {
PGPSecretKey key = (PGPSecretKey) keyIter.next();
if (key.isSigningKey()) {
return key;
}
}
}
throw new IllegalArgumentException(
"Can't find signing key in key ring.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment