Example usage for org.bouncycastle.openpgp PGPUtil writeFileToLiteralData

List of usage examples for org.bouncycastle.openpgp PGPUtil writeFileToLiteralData

Introduction

In this page you can find the example usage for org.bouncycastle.openpgp PGPUtil writeFileToLiteralData.

Prototype

public static void writeFileToLiteralData(OutputStream out, char fileType, File file) throws IOException 

Source Link

Document

Write out the contents of the provided file as a literal data packet.

Usage

From source file:gr.abiss.calipso.util.PgpUtils.java

License:Open Source License

static byte[] compressFile(String fileName, int algorithm) throws IOException {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(algorithm);
    PGPUtil.writeFileToLiteralData(comData.open(bOut), PGPLiteralData.BINARY, new File(fileName));
    comData.close();/* www  .ja  va  2 s. c  o  m*/
    return bOut.toByteArray();
}

From source file:hh.learnj.test.license.test.lincense3j.MyPGPUtil.java

public static byte[] compressFile(String fileName, int algorithm) throws IOException {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(algorithm);
    PGPUtil.writeFileToLiteralData(comData.open(bOut), PGPLiteralData.BINARY, new File(fileName));
    comData.close();/*from  w  w w. j  a  v  a2s .  co  m*/
    return bOut.toByteArray();
}

From source file:net.tjado.passwdsafe.UsbGpgBackupActivity.java

License:Open Source License

public static void encryptFile(OutputStream out, String fileName, PGPPublicKey encKey)
        throws IOException, PGPException {
    Security.addProvider(new BouncyCastleProvider());

    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(PGPCompressedData.ZLIB);

    PGPUtil.writeFileToLiteralData(comData.open(bOut), PGPLiteralData.BINARY, new File(fileName));
    comData.close();/*from   w  ww  .  jav  a 2s  . co m*/

    PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(
            new BcPGPDataEncryptorBuilder(SymmetricKeyAlgorithmTags.AES_256).setSecureRandom(new SecureRandom())
                    .setWithIntegrityPacket(true));
    cPk.addMethod(new BcPublicKeyKeyEncryptionMethodGenerator(encKey));

    byte[] bytes = bOut.toByteArray();

    OutputStream cOut;
    cOut = cPk.open(out, bytes.length);
    cOut.write(bytes);
    cOut.close();

    out.close();
}