Skip navigation links

@ParametersAreNonnullByDefault

Package com.pkware.smartcrypt.unstructured

The Smartcrypt Unstructured Data package is particularly useful when encrypting data stored in files and other unstructured containers.

See: Description

Package com.pkware.smartcrypt.unstructured Description

The Smartcrypt Unstructured Data package is particularly useful when encrypting data stored in files and other unstructured containers. ZIP archives are used for compression and encryption. Accordingly, large data sets benefit from this component.

Encryption

MetaClient metaClient = new NativeMetaClient.Builder()
         .appName("UnstructuredEncryptionSample")
         .appVersion("9.99.9999")
         .deviceName(UUID.randomUUID().toString())
         .deviceUniqueId(UUID.randomUUID().toString())
         .platform(Platform.LINUX)
         .platformVersion("0")
         .build();

 UnstructuredData unstructuredData = new UnstructuredDataImpl.Builder()
         .metaClient(metaClient)
         .license("{your license here}")
         .build();

 File exampleFile = new File("example.zip");
 EncryptionSpec spec = new EncryptionSpec();
 spec.smartkey = smartkey;
 spec.password = "password";
 try (OutputStream targetStream = new FileOutputStream(exampleFile)) {
     try (ZipArchiveOutputStream archive = unstructuredData.newZipOutputStream(targetStream)) {
         unstructuredData.encrypt(archive, spec);
         InputStream sourceStream = new ByteArrayInputStream("Hello, world!".getBytes());
         ZipArchiveEntry entry = archive.createArchiveEntry(null, "message.txt");
         archive.addEntry(entry, sourceStream);
     }
 }
 

Decryption

MetaClient metaClient = new NativeMetaClient.Builder()
         .appName("UnstructuredEncryptionSample")
         .appVersion("9.99.9999")
         .deviceName(UUID.randomUUID().toString())
         .deviceUniqueId(UUID.randomUUID().toString())
         .platform(Platform.LINUX)
         .platformVersion("0")
         .build();

 UnstructuredData unstructuredData = new UnstructuredDataImpl.Builder()
         .metaClient(metaClient)
         .license("{your license here}")
         .build();

 File exampleFile = new File("example.zip");
 ZipFile archive = unstructuredData.newZipFile(exampleFile);
 ZipArchiveEntry entry = archive.getEntry("message.txt");
 try (InputStream entryStream = archive.getInputStream(entry)) {
     try (OutputStream targetFile = new FileOutputStream("message.txt")) {
         IOUtils.copy(entryStream, targetFile);
     }
 }
 archive.close();
 
Skip navigation links
Copyright 2012-2019, PKWARE, Inc.