private static PGPLiteralData asLiteral( final byte[] message, final InputStream secretKeyRing, final String secretPwd ) throws IOException, PGPException { PGPPrivateKey key = null; PGPPublicKeyEncryptedData encrypted = null; final PGPSecretKeyRingCollection keys = new PGPSecretKeyRingCollection( PGPUtil.getDecoderStream( secretKeyRing ), new JcaKeyFingerprintCalculator() ); for ( final Iterator<PGPPublicKeyEncryptedData> i = getEncryptedObjects( message ); ( key == null ) && i.hasNext(); ) { encrypted = i.next(); key = getPrivateKey( keys, encrypted.getKeyID(), secretPwd ); } if ( key == null ) { throw new IllegalArgumentException( "secret key for message not found." ); } final InputStream stream = encrypted .getDataStream( new JcePublicKeyDataDecryptorFactoryBuilder().setProvider( provider ).build( key ) ); return asLiteral( stream ); }
private static PGPLiteralData asLiteral( final byte[] data, final InputStream keyfile, final String passphrase) throws IOException, PGPException { PGPPrivateKey key = null; PGPPublicKeyEncryptedData encrypted = null; final PGPSecretKeyRingCollection keys = new PGPSecretKeyRingCollection(new ArmoredInputStream(keyfile), new BcKeyFingerprintCalculator()); for (final Iterator<PGPPublicKeyEncryptedData> i = getEncryptedObjects(data); key == null && i.hasNext();) { encrypted = i.next(); key = findSecretKey(keys, encrypted.getKeyID(), passphrase); } if (key == null) { throw new IllegalArgumentException("secret key for message not found."); } final InputStream stream = encrypted.getDataStream( new JcePublicKeyDataDecryptorFactoryBuilder() .setProvider(PROVIDER) .build(key)); return asLiteral(stream); }
/** * * @deprecated use the method taking a PublicKeyDataDecryptorFactory */ public int getSymmetricAlgorithm( PGPPrivateKey privKey, Provider provider) throws PGPException, NoSuchProviderException { return getSymmetricAlgorithm(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider(provider).setContentProvider(provider).build(privKey)); }
/** * @deprecated use method that takes a PublicKeyDataDecryptorFactory */ public InputStream getDataStream( PGPPrivateKey privKey, Provider asymProvider, Provider provider) throws PGPException { return getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider(asymProvider).setContentProvider(provider).build(privKey)); }
private static InputStream getInputStream( PGPPrivateKey privateKey, PGPPublicKeyEncryptedData pgpEncData ) throws PGPException, IOException { InputStream is = pgpEncData .getDataStream( new JcePublicKeyDataDecryptorFactoryBuilder().setProvider( "BC" ).build( privateKey ) ); JcaPGPObjectFactory objectFactory = new JcaPGPObjectFactory( is ); Object message = objectFactory.nextObject(); PGPCompressedData compressedData = ( PGPCompressedData ) message; JcaPGPObjectFactory pgpObjectFactory = new JcaPGPObjectFactory( compressedData.getDataStream() ); PGPLiteralData literalData = ( PGPLiteralData ) pgpObjectFactory.nextObject(); return literalData.getInputStream(); }