7.4 Peeking a Sealed File and Checking the Digital Signature

The following code demonstrates how to extract the metadata from sealed content using the validatedPeek method. Once peeked, the file metadata, which includes the Classification details, can be examined. The sample code prints out the human readable classification details (the labels) that were sealed into the content.

The validatedPeek method attempts to check the public header against its declared signature. If the public header metadata has been altered post-sealing, this method will throw an exception.

Example 7-3

import static oracle.irm.engine.content.sealing.SealingOperationsInstance.validatedPeek;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.net.Authenticator;
 import java.net.PasswordAuthentication;
 import oracle.irm.engine.content.sealing.ContentDescription;
 import oracle.irm.engine.core.classification.Classification;
 import oracle.irm.engine.core.general.Label;
 public class ValidatedPeekFile {
     public static void main(String[] args) throws IOException {
         // The user name and password are provided on the command line. In a production
         // system these details should be provided in a more secure manner, such
         // as prompting from the console, or reading from a secure source.
         final String username = args[0];
         final String password = args[1];
         // Configure an authenticator to provide the credentials for any network access
         Authenticator.setDefault(new Authenticator() {
             protected PasswordAuthentication getPasswordAuthentication() {
                 return new PasswordAuthentication(username, password.toCharArray());
        // The name of the file to peek
         FileInputStream stream = new FileInputStream(args[2]);
         // Perform the peek, providing a stream to the sealed file
         ContentDescription contentDescription = validatedPeek(stream);
         // Close the file stream
         // Extract the classification details from the content
         Classification classification = contentDescription.getClassification();
         // Show all the labels sealed into content
         for (Label label : classification.getLabels()) {
             System.out.println(label.getLocale().getDisplayName() + " : " + label.getName());