/** * Build a PGPPublicKeyRingCollection from the passed in input stream. * * @param in input stream containing data * @throws IOException if a problem parsing the base stream occurs * @throws PGPException if an object is encountered which isn't a PGPPublicKeyRing */ public PGPPublicKeyRingCollection( InputStream in, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException, PGPException { PGPObjectFactory pgpFact = new PGPObjectFactory(in, fingerPrintCalculator); Object obj; while ((obj = pgpFact.nextObject()) != null) { if (!(obj instanceof PGPPublicKeyRing)) { throw new PGPException(obj.getClass().getName() + " found where PGPPublicKeyRing expected"); } PGPPublicKeyRing pgpPub = (PGPPublicKeyRing)obj; Long key = new Long(pgpPub.getPublicKey().getKeyID()); pubRings.put(key, pgpPub); order.add(key); } }
/** * Build a PGPSecretKeyRingCollection from the passed in input stream. * * @param in input stream containing data * @throws IOException if a problem parsinh the base stream occurs * @throws PGPException if an object is encountered which isn't a PGPSecretKeyRing */ public PGPSecretKeyRingCollection( InputStream in, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException, PGPException { PGPObjectFactory pgpFact = new PGPObjectFactory(in, fingerPrintCalculator); Object obj; while ((obj = pgpFact.nextObject()) != null) { if (!(obj instanceof PGPSecretKeyRing)) { throw new PGPException(obj.getClass().getName() + " found where PGPSecretKeyRing expected"); } PGPSecretKeyRing pgpSecret = (PGPSecretKeyRing)obj; Long key = new Long(pgpSecret.getPublicKey().getKeyID()); secretRings.put(key, pgpSecret); order.add(key); } }
PGPPublicKey( PublicKeyPacket publicPk, TrustPacket trustPk, List keySigs, List ids, List idTrusts, List idSigs, KeyFingerPrintCalculator fingerPrintCalculator) throws PGPException { this.publicPk = publicPk; this.trustPk = trustPk; this.keySigs = keySigs; this.ids = ids; this.idTrusts = idTrusts; this.idSigs = idSigs; init(fingerPrintCalculator); }
private static List<PGPSecretKeyRing> extractSecrectKeyRings(InputStream inputStream) { InputStream decodedInput; try { decodedInput = PGPUtil.getDecoderStream(inputStream); } catch (final IOException e) { throw JkUtilsThrowable.unchecked(e); } final KeyFingerPrintCalculator fingerPrintCalculator = new JcaKeyFingerprintCalculator(); final InnerPGPObjectFactory pgpFact = new InnerPGPObjectFactory(decodedInput, fingerPrintCalculator); PGPSecretKeyRing secKeyRing; final List<PGPSecretKeyRing> result = new LinkedList<>(); while ((secKeyRing = pgpFact.nextSecretKey()) != null) { result.add(secKeyRing); } return result; }
public PGPPublicKeyRingCollection( byte[] encoding, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException, PGPException { this(new ByteArrayInputStream(encoding), fingerPrintCalculator); }
public PGPSecretKeyRing( byte[] encoding, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException, PGPException { this(new ByteArrayInputStream(encoding), fingerPrintCalculator); }
/** * Create an object factory suitable for reading PGP objects such as keys, key rings and key * ring collections, or PGP encrypted data. * * @param in stream to read PGP data from. * @param fingerPrintCalculator calculator to use in key finger print calculations. */ public PGPObjectFactory( InputStream in, KeyFingerPrintCalculator fingerPrintCalculator) { this.in = new BCPGInputStream(in); this.fingerPrintCalculator = fingerPrintCalculator; }
public PGPSecretKeyRingCollection( byte[] encoding, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException, PGPException { this(new ByteArrayInputStream(encoding), fingerPrintCalculator); }
private void init(KeyFingerPrintCalculator fingerPrintCalculator) throws PGPException { BCPGKey key = publicPk.getKey(); this.fingerprint = fingerPrintCalculator.calculateFingerprint(publicPk); if (publicPk.getVersion() <= 3) { RSAPublicBCPGKey rK = (RSAPublicBCPGKey)key; this.keyID = rK.getModulus().longValue(); this.keyStrength = rK.getModulus().bitLength(); } else { this.keyID = ((long)(fingerprint[fingerprint.length - 8] & 0xff) << 56) | ((long)(fingerprint[fingerprint.length - 7] & 0xff) << 48) | ((long)(fingerprint[fingerprint.length - 6] & 0xff) << 40) | ((long)(fingerprint[fingerprint.length - 5] & 0xff) << 32) | ((long)(fingerprint[fingerprint.length - 4] & 0xff) << 24) | ((long)(fingerprint[fingerprint.length - 3] & 0xff) << 16) | ((long)(fingerprint[fingerprint.length - 2] & 0xff) << 8) | ((fingerprint[fingerprint.length - 1] & 0xff)); if (key instanceof RSAPublicBCPGKey) { this.keyStrength = ((RSAPublicBCPGKey)key).getModulus().bitLength(); } else if (key instanceof DSAPublicBCPGKey) { this.keyStrength = ((DSAPublicBCPGKey)key).getP().bitLength(); } else if (key instanceof ElGamalPublicBCPGKey) { this.keyStrength = ((ElGamalPublicBCPGKey)key).getP().bitLength(); } } }
/** * Create a PGP public key from a packet descriptor using the passed in fingerPrintCalculator to do calculate * the fingerprint and keyID. * * @param publicKeyPacket packet describing the public key. * @param fingerPrintCalculator calculator providing the digest support ot create the key fingerprint. * @throws PGPException if the packet is faulty, or the required calculations fail. */ public PGPPublicKey(PublicKeyPacket publicKeyPacket, KeyFingerPrintCalculator fingerPrintCalculator) throws PGPException { this.publicPk = publicKeyPacket; this.ids = new ArrayList(); this.idSigs = new ArrayList(); init(fingerPrintCalculator); }
PGPPublicKey( PublicKeyPacket publicPk, TrustPacket trustPk, List sigs, KeyFingerPrintCalculator fingerPrintCalculator) throws PGPException { this.publicPk = publicPk; this.trustPk = trustPk; this.subSigs = sigs; init(fingerPrintCalculator); }
public PGPPublicKeyRing( byte[] encoding, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException { this(new ByteArrayInputStream(encoding), fingerPrintCalculator); }
static PGPPublicKey readSubkey(BCPGInputStream in, KeyFingerPrintCalculator fingerPrintCalculator) throws IOException, PGPException { PublicKeyPacket pk = (PublicKeyPacket)in.readPacket(); TrustPacket kTrust = readOptionalTrustPacket(in); // PGP 8 actually leaves out the signature. List sigList = readSignaturesAndTrust(in); return new PGPPublicKey(pk, kTrust, sigList, fingerPrintCalculator); }
/** * Create an object factor suitable for reading keys, key rings and key ring collections. * * @param in stream to read from * @param fingerPrintCalculator calculator to use in key finger print calculations. */ public PGPObjectFactory( InputStream in, KeyFingerPrintCalculator fingerPrintCalculator) { this.in = new BCPGInputStream(in); this.fingerPrintCalculator = fingerPrintCalculator; }
/** * Create an object factor suitable for reading keys, key rings and key ring collections. * * @param bytes stream to read from * @param fingerPrintCalculator calculator to use in key finger print calculations. */ public PGPObjectFactory( byte[] bytes, KeyFingerPrintCalculator fingerPrintCalculator) { this(new ByteArrayInputStream(bytes), fingerPrintCalculator); }