Package com.bfo.box
Class C2PAStore
java.lang.Object
com.bfo.box.Box
com.bfo.box.JUMBox
com.bfo.box.C2PAStore
The store box
is the top-level box for any C2PA object. It contains one or more manifest boxes
which must be added to getManifests()
Here's an example showing how to create a new C2PAStore. It uses the C2PAHelper class to embed the store in JPEG file.
C2PAStore c2pa = new C2PAStore(); C2PAManifest manifest = new C2PAManifest("urn:manifestid"); c2pa.getManifests().add(manifest); C2PAClaim claim = manifest.getClaim(); C2PASignature sig = manifest.getSignature(); claim.setFormat("image/jpeg"); claim.setInstanceID("urn:instanceid"); manifest.getAssertions().add(new C2PA_AssertionHashData()); Json schemaJson = Json.read("{\"@context\":\"https://schema.org/\",\"@type\":\"VideoObject\",\"name\":\"LearnJSON-LD\",\"author\":{\"@type\":\"Person\",\"name\":\"Foo Bar\"}}"); manifest.getAssertions().add(new C2PA_AssertionSchema("stds.schema-org.CreativeWork", schemaJson)); KeyStore keystore = KeyStore.getInstance("PKCS12"); keystore.load(new FileInputStream(keystorefile), keystorepassword); PrivateKey key = (PrivateKey)keystore.getKey(keystorealias, keystorepassword); List<gX509Certificate> certs = new ArrayList<X509Certificate>(); for (Certificate c : keystore.getCertificateChain(keystorealias)) { certs.add((X509Certificate)c); } manifest.getSignature().setSigner(key, certs); Json j = C2PAHelper.readJPEG(new FileInputStream("unsigned.jpg")); C2PAHelper.writeJPEG(j, c2pa, new FileOutputStream("signed.jpg"));and here's an example showing how to read the file back and verify it
Json j = C2PAHelper.readJPEG(new FileInputStream("signed.jpg")); if (j.has("c2pa")) { C2PAStore c2pa = (C2PAStore)new BoxFactory().load(j.bufferValue("c2pa")); C2PAManifest manifest = c2pa.getActiveManifest(); manifest.setInputStream(new FileInputStream("signed.jpg")); boolean valid = true; for (C2PAStatus status : manifest.getSignature().verify(null)) { System.out.println(status); if (status.isError()) { valid = false; } } }
- Since:
- 5
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturn the active manifest, which is just the last one in the list returned bygetManifests()
Return a live list of themanifest
objects in this storetoJson()
Return a representation of this store as a single Json object.
-
Constructor Details
-
C2PAStore
public C2PAStore()Create a new C2PAStore
-
-
Method Details
-
getManifests
Return a live list of themanifest
objects in this store- Returns:
- the list of manifests
-
getActiveManifest
Return the active manifest, which is just the last one in the list returned bygetManifests()
- Returns:
- the active manifest
-
toJson
Return a representation of this store as a single Json object. The returned value is not live, changes will not affect this object. The object should be largely comparable to the output fromc2patool
- Returns:
- the json
-