Java Code Examples for org.bouncycastle.openpgp.PGPSecretKeyRingCollection#getKeyRings()
The following examples show how to use
org.bouncycastle.openpgp.PGPSecretKeyRingCollection#getKeyRings() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AptSigningFacet.java From nexus-repository-apt with Eclipse Public License 1.0 | 6 votes |
private PGPSecretKey readSecretKey() throws IOException, PGPException { PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection( PGPUtil.getDecoderStream(new ByteArrayInputStream(config.keypair.getBytes())), new JcaKeyFingerprintCalculator()); Iterator<PGPSecretKeyRing> keyRings = pgpSec.getKeyRings(); while (keyRings.hasNext()) { PGPSecretKeyRing keyRing = (PGPSecretKeyRing) keyRings.next(); Iterator<PGPSecretKey> keys = keyRing.getSecretKeys(); while (keys.hasNext()) { PGPSecretKey key = (PGPSecretKey) keys.next(); if (key.isSigningKey()) { return key; } } } throw new IllegalStateException("Can't find signing key in key ring."); }
Example 2
Source File: AptSigningFacet.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
private PGPSecretKey readSecretKey() throws IOException { try { PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection( PGPUtil.getDecoderStream(new ByteArrayInputStream(config.keypair.getBytes(Charsets.UTF_8))), new JcaKeyFingerprintCalculator()); Iterator<PGPSecretKeyRing> keyRings = pgpSec.getKeyRings(); while (keyRings.hasNext()) { PGPSecretKeyRing keyRing = keyRings.next(); Iterator<PGPSecretKey> keys = keyRing.getSecretKeys(); while (keys.hasNext()) { PGPSecretKey key = keys.next(); if (key.isSigningKey()) { return key; } } } } catch (PGPException ex) { throw new RuntimeException(ex); } throw new IllegalStateException("Can't find signing key in key ring."); }
Example 3
Source File: PGPKeyHelper.java From peer-os with Apache License 2.0 | 5 votes |
private static PGPSecretKey readSecretKey( InputStream is ) throws IOException, PGPException { PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection( PGPUtil.getDecoderStream( is ), new JcaKeyFingerprintCalculator() ); 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." ); }
Example 4
Source File: OpenPGPSignatureGenerator.java From ant-ivy with Apache License 2.0 | 5 votes |
private PGPSecretKey readSecretKey(InputStream in) throws IOException, PGPException { in = PGPUtil.getDecoderStream(in); PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(in, new BcKeyFingerprintCalculator()); PGPSecretKey key = null; Iterator<PGPSecretKeyRing> it = pgpSec.getKeyRings(); while (key == null && it.hasNext()) { PGPSecretKeyRing kRing = it.next(); Iterator<PGPSecretKey> it2 = kRing.getSecretKeys(); while (key == null && it2.hasNext()) { PGPSecretKey k = it2.next(); if (keyId == null && k.isSigningKey()) { key = k; } if (keyId != null && Long.valueOf(keyId, 16) == (k.getKeyID() & MASK)) { key = k; } } } if (key == null) { throw new IllegalArgumentException("Can't find encryption key" + (keyId != null ? " '" + keyId + "' " : " ") + "in key ring."); } return key; }