List of usage examples for org.bouncycastle.openpgp PGPLiteralData NOW
Date NOW
To view the source code for org.bouncycastle.openpgp PGPLiteralData NOW.
Click Source Link
From source file:com.geoxp.oss.CryptoHelper.java
License:Apache License
public static byte[] encryptPGP(byte[] data, PGPPublicKey key, boolean armored, String name, int compressionAlgorithm, int encAlgorithm) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream out = armored ? new ArmoredOutputStream(baos) : baos; BcPGPDataEncryptorBuilder dataEncryptor = new BcPGPDataEncryptorBuilder(encAlgorithm); dataEncryptor.setWithIntegrityPacket(true); dataEncryptor.setSecureRandom(CryptoHelper.getSecureRandom()); PGPEncryptedDataGenerator encryptedDataGenerator = new PGPEncryptedDataGenerator(dataEncryptor); encryptedDataGenerator.addMethod(new BcPublicKeyKeyEncryptionMethodGenerator(key)); try {/* www .j ava 2 s. c o m*/ OutputStream encout = encryptedDataGenerator.open(out, 1024); PGPCompressedDataGenerator pgpcdg = new PGPCompressedDataGenerator(compressionAlgorithm); OutputStream compout = pgpcdg.open(encout); PGPLiteralDataGenerator pgpldg = new PGPLiteralDataGenerator(false); OutputStream ldout = pgpldg.open(compout, PGPLiteralData.BINARY, name, data.length, PGPLiteralData.NOW); ldout.write(data); ldout.close(); compout.close(); encout.close(); out.close(); baos.close(); return baos.toByteArray(); } catch (PGPException pgpe) { throw new IOException(pgpe); } }
From source file:com.google.gerrit.server.contact.EncryptedContactStore.java
License:Apache License
private static byte[] compress(final String fileName, Date fileDate, final byte[] plainText) throws IOException { final ByteArrayOutputStream buf = new ByteArrayOutputStream(); final PGPCompressedDataGenerator comdg; final int len = plainText.length; if (fileDate == null) { fileDate = PGPLiteralData.NOW; }// ww w . ja v a 2 s . c o m comdg = new PGPCompressedDataGenerator(PGPCompressedData.ZIP); final OutputStream out = new PGPLiteralDataGenerator().open(comdg.open(buf), PGPLiteralData.BINARY, fileName, len, fileDate); out.write(plainText); out.close(); comdg.close(); return buf.toByteArray(); }