List of usage examples for org.bouncycastle.openpgp PGPSecretKeyRing getPublicKey
public PGPPublicKey getPublicKey()
From source file:org.jivesoftware.smackx.ox.OpenPgpSelf.java
License:Apache License
/** * Return the {@link PGPSecretKeyRing} which we will use to sign our messages. * @return signing key//ww w . j a v a 2 s . c o m * @throws IOException IO is dangerous * @throws PGPException PGP is brittle */ public PGPSecretKeyRing getSigningKeyRing() throws IOException, PGPException { PGPSecretKeyRingCollection secretKeyRings = getSecretKeys(); if (secretKeyRings == null) { return null; } PGPSecretKeyRing signingKeyRing = null; for (PGPSecretKeyRing ring : secretKeyRings) { if (signingKeyRing == null) { signingKeyRing = ring; continue; } if (ring.getPublicKey().getCreationTime().after(signingKeyRing.getPublicKey().getCreationTime())) { signingKeyRing = ring; } } return signingKeyRing; }
From source file:org.jivesoftware.smackx.ox.OpenPgpSelf.java
License:Apache License
/** * Return the {@link OpenPgpV4Fingerprint} of our signing key. * @return fingerprint of signing key/* www. j ava2 s . c o m*/ * @throws IOException IO is dangerous * @throws PGPException PGP is brittle */ public OpenPgpV4Fingerprint getSigningKeyFingerprint() throws IOException, PGPException { PGPSecretKeyRing signingKeyRing = getSigningKeyRing(); return signingKeyRing != null ? new OpenPgpV4Fingerprint(signingKeyRing.getPublicKey()) : null; }
From source file:org.jivesoftware.smackx.ox.OpenPgpSelf.java
License:Apache License
/** * Return a {@link PGPPublicKeyRingCollection} containing only the public keys belonging to our signing key ring. * TODO: Add support for public keys of other devices of the owner. * * @return public keys//from w ww .j a va 2s. c o m * * @throws IOException IO is dangerous. * @throws PGPException PGP is brittle. */ @Override public PGPPublicKeyRingCollection getAnnouncedPublicKeys() throws IOException, PGPException { PGPSecretKeyRing secretKeys = getSigningKeyRing(); PGPPublicKeyRing publicKeys = getAnyPublicKeys().getPublicKeyRing(secretKeys.getPublicKey().getKeyID()); publicKeys = BCUtil.removeUnassociatedKeysFromKeyRing(publicKeys, secretKeys.getPublicKey()); return new PGPPublicKeyRingCollection(Collections.singleton(publicKeys)); }
From source file:org.jivesoftware.smackx.ox.store.abstr.AbstractOpenPgpKeyStore.java
License:Apache License
@Override public void importSecretKey(BareJid owner, PGPSecretKeyRing secretKeys) throws IOException, PGPException, MissingUserIdOnKeyException { // TODO: Avoid 'new' use instance method. if (!new BareJidUserId.SecRingSelectionStrategy().accept(owner, secretKeys)) { throw new MissingUserIdOnKeyException(owner, new OpenPgpV4Fingerprint(secretKeys)); }/* w w w. ja v a 2 s .c om*/ PGPSecretKeyRing importKeys = BCUtil.removeUnassociatedKeysFromKeyRing(secretKeys, secretKeys.getPublicKey()); PGPSecretKeyRingCollection secretKeyRings = getSecretKeysOf(owner); try { if (secretKeyRings != null) { secretKeyRings = PGPSecretKeyRingCollection.addSecretKeyRing(secretKeyRings, importKeys); } else { secretKeyRings = BCUtil.keyRingsToKeyRingCollection(importKeys); } } catch (IllegalArgumentException e) { LOGGER.log(Level.INFO, "Skipping secret key ring " + Long.toHexString(importKeys.getPublicKey().getKeyID()) + " as it is already in the key ring of " + owner.toString()); } this.secretKeyRingCollections.put(owner, secretKeyRings); writeSecretKeysOf(owner, secretKeyRings); }
From source file:org.pgptool.gui.encryption.implpgp.KeyFilesOperationsPgpImpl.java
License:Open Source License
protected static KeyInfo buildKeyInfoFromSecret(PGPSecretKeyRing secretKeyRing) throws PGPException { KeyInfo ret = new KeyInfo(); ret.setKeyType(KeyTypeEnum.KeyPair); PGPPublicKey key = secretKeyRing.getPublicKey(); ret.setUser(buildUser(key.getUserIDs())); ret.setKeyId(KeyDataPgp.buildKeyIdStr(key.getKeyID())); fillDates(ret, key);/*from ww w. j a v a2s. c o m*/ fillAlgorithmName(ret, key); return ret; }
From source file:org.sufficientlysecure.keychain.pgp.PgpKeyOperation.java
License:Open Source License
/** This method returns true iff the provided keyring has a local direct key signature * with notation data./*from w w w .j ava2 s .c o m*/ */ private static boolean hasNotationData(PGPSecretKeyRing sKR) { // noinspection unchecked Iterator<PGPSignature> sigs = sKR.getPublicKey().getKeySignatures(); while (sigs.hasNext()) { WrappedSignature sig = new WrappedSignature(sigs.next()); if (sig.getSignatureType() == PGPSignature.DIRECT_KEY && sig.isLocal() && !sig.getNotation().isEmpty()) { return true; } } return false; }
From source file:ubicrypt.core.crypto.PGPKeyRingImpl.java
License:Open Source License
private void readPrivateKeyBundle() throws Exception { final InputStream in = new FileInputStream(getSecretKeyRingFileName()); final PGPSecretKeyRingCollection collection = new PGPSecretKeyRingCollection(in, new BcKeyFingerprintCalculator()); in.close();/*from ww w . jav a2s.co m*/ final Iterator iter = collection.getKeyRings(); while (iter.hasNext()) { final PGPSecretKeyRing sec = (PGPSecretKeyRing) iter.next(); final Iterator userids = sec.getPublicKey().getUserIDs(); while (userids.hasNext()) { final String uid = (String) userids.next(); } } secretKey = collection.getSecretKey(Long.valueOf(getSecretAliasId())); if (secretKey == null) { final StringBuilder message = new StringBuilder(); message.append('\n'); final Iterator iterator = collection.getKeyRings(); while (iterator.hasNext()) { final PGPSecretKeyRing ring = (PGPSecretKeyRing) iterator.next(); final Iterator secretKeysIterator = ring.getSecretKeys(); while (secretKeysIterator.hasNext()) { final PGPSecretKey k = (PGPSecretKey) secretKeysIterator.next(); message.append("Key: "); message.append(k.getKeyID()); message.append('\n'); } } throw new Exception("no secret found but available:" + message.toString()); } }