Example usage for org.bouncycastle.cms CMSCompressedData getEncoded

List of usage examples for org.bouncycastle.cms CMSCompressedData getEncoded

Introduction

In this page you can find the example usage for org.bouncycastle.cms CMSCompressedData getEncoded.

Prototype

public byte[] getEncoded() throws IOException 

Source Link

Document

return the ASN.1 encoded representation of this object.

Usage

From source file:chapter9.CompressedDataExample.java

/**
 *
 * @param args//from  w  w  w.  j  ava2 s . c  o  m
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    //1.- Set up the generator
    CMSCompressedDataGenerator gen = new CMSCompressedDataGenerator();

    //2.- Compress the data
    CMSProcessableByteArray data = new CMSProcessableByteArray("Hello World!!".getBytes());

    CMSCompressedData compressed = gen.generate(data, CMSCompressedDataGenerator.ZLIB);

    System.out.println(Utils.base64Encode(compressed.getEncoded()));

    //3.- Re-create and uncompress the data
    compressed = new CMSCompressedData(compressed.getEncoded());

    byte[] recData = compressed.getContent();

    //4.- Compare uncompressed data to the original
    if (Arrays.equals((byte[]) data.getContent(), recData) == true)
        System.out.println("\t data recovery succeeded!!");
    else
        System.out.println("\t Could not find a matching recipient!!");
}

From source file:io.aos.crypto.spl09.CompressedDataExample.java

License:Apache License

public static void main(String... args) throws Exception {
    // set up the generator
    CMSCompressedDataGenerator gen = new CMSCompressedDataGenerator();

    //compress the data
    CMSProcessableByteArray data = new CMSProcessableByteArray("Hello world!".getBytes());

    CMSCompressedData compressed = gen.generate(data, CMSCompressedDataGenerator.ZLIB);

    // recreate and uncompress the data
    compressed = new CMSCompressedData(compressed.getEncoded());

    byte[] recData = compressed.getContent();

    // compare uncompressed data to the original data
    if (Arrays.equals((byte[]) data.getContent(), recData)) {
        System.out.println("data recovery succeeded");
    } else {// w w w  . jav  a 2  s  .  com
        System.out.println("data recovery failed");
    }
}