I search a method for insert a digest (byte array or String) into PDF file using iText library (Java). I create the digest from a String with this method:
private String crypt(double x, ByteArrayOutputStream baos) throws UnsupportedEncodingException, NoSuchAlgorithmException{
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(String.valueOf(x).getBytes("UTF-8"));
md.update(String.valueOf(baos).getBytes("UTF-8"));
byte[] digest = md.digest();
StringBuffer sb = new StringBuffer();
for(byte d:digest){
sb.append(Integer.toHexString(0xFF & d));
}
return sb.toString();
}
The digest should be not seen in PDF, but it must be exctracted for comparison.
Such private data can be stored in PieceInfo dictionaries:
In your case the PieceInfo in the document catalogue seem most apropos.
Using iText you can store data there and retrieve them back again like this using the
DocumentPieceInfo
helper class below:Storing document PieceInfo data
Retrieving document PieceInfo data
The
DocumentPieceInfo
helper classThis class assumes the Private value to be a dictionary in which in turn the private data are stored. It may be anything, though. To process the private data generated by other programs, you may need some variation.