List of usage examples for org.bouncycastle.openpgp PGPLiteralDataGenerator UTF8
char UTF8
To view the source code for org.bouncycastle.openpgp PGPLiteralDataGenerator UTF8.
Click Source Link
From source file:fi.csc.emrex.smp.openpgp.PGPEncryptionUtil.java
public PGPEncryptionUtil(PGPPublicKey key, String payloadFilename, OutputStream out) throws PGPException, NoSuchProviderException, IOException { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); // write data out using "ascii-armor" encoding. This is the // normal PGP text output. this.armoredOutputStream = new ArmoredOutputStream(out); // create an encrypted payload and set the public key on the data generator PGPEncryptedDataGenerator encryptGen = new PGPEncryptedDataGenerator(PAYLOAD_ENCRYPTION_ALG, new SecureRandom(), BC_PROVIDER_NAME); encryptGen.addMethod(key);//from w ww . ja v a 2 s . c om // open an output stream connected to the encrypted data generator // and have the generator write its data out to the ascii-encoding stream this.encryptedOut = encryptGen.open(armoredOutputStream, new byte[BUFFER_SIZE]); // compress data. we are building layers of output streams. we want to compress here // because this is "before" encryption, and you get far better compression on // unencrypted data. PGPCompressedDataGenerator compressor = new PGPCompressedDataGenerator(PGPCompressedData.ZIP); this.compressedOut = compressor.open(encryptedOut); // now we have a stream connected to a data compressor, which is connected to // a data encryptor, which is connected to an ascii-encoder. // into that we want to write a PGP "literal" object, which is just a named // piece of data (as opposed to a specially-formatted key, signature, etc) PGPLiteralDataGenerator literalGen = new PGPLiteralDataGenerator(); this.literalOut = literalGen.open(compressedOut, PGPLiteralDataGenerator.UTF8, payloadFilename, new Date(), new byte[BUFFER_SIZE]); }