Package com.bfo.box
Class C2PAHelper
java.lang.Object
com.bfo.box.C2PAHelper
A general Helper class for C2PA which functions as a main method, provides
utility methods for embedding C2PA in files. See
C2PAStore
for
details on how to use it- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
static Json
readJPEG
(InputStream in) Read a JPEG image from the supplied InputStream and return a Json object describing various aspects of it that are relevant for C2PA.static List<C2PAStatus>
writeJPEG
(Json image, C2PAStore store, OutputStream out) Save a JPEG, signing and inserting the supplied C2PAStore.
-
Constructor Details
-
C2PAHelper
public C2PAHelper()
-
-
Method Details
-
readJPEG
Read a JPEG image from the supplied InputStream and return a Json object describing various aspects of it that are relevant for C2PA.-
c2pa - if the JPEG image contains a C2PA object, this will
be set to a
buffer
containing the encoded C2PA object -
xmp - if the JPEG image contains an XMP block, this will
be set to a
buffer
containing the XMP data -
data - a
buffer
which contains the image data after the C2PA and XMP are removed - insert_offset - an offset into the "data" object that is the suggested location of any new C2PA or XMP data.
- Parameters:
in
- the InputStream (required)- Returns:
- the data as described
- Throws:
IOException
- if the object failed to load
-
c2pa - if the JPEG image contains a C2PA object, this will
be set to a
-
writeJPEG
public static List<C2PAStatus> writeJPEG(Json image, C2PAStore store, OutputStream out) throws IOException Save a JPEG, signing and inserting the supplied C2PAStore.-
data - a
buffer
which contains the image data after the C2PA and XMP are removed - insert_offset - the offset into the "data" object that is the location of any the C2PA and XMP data.
- xmp - (optional) a string or bytebuffer that contains the XMP data to insert. If this value is zero length, or is any other value other than null, a basic XMP will be created and inserted.
After this method exits, the
image
parameter will be updated to add ac2pa
, which is encoded version of the C2PA object that was written.The C2PA store supplied must have an active manifest with a
C2PA_AssertionHashData
and that has hadC2PASignature.setSigner(java.security.PrivateKey, java.util.List<java.security.cert.X509Certificate>)
called on it.- Parameters:
image
- the image data, which must have at leastdata
andinsert_offset
store
- the C2PA store to insertout
- the OutputStream to write to- Returns:
- the list of C2PA status codes from signing
- Throws:
IOException
- if the object failed to save
-
data - a
-
main
- Throws:
Exception
-