-1

When I try to verify a timestamp using the Java library, I am running into a Java NullPointerException.

I'm following the examples in the README of https://github.com/opentimestamps/java-opentimestamps

This is my code:

byte[] originalFile = Files.readAllBytes(fileData.get("absoluteFilePath"));     
byte[] originalBytes = new String(originalFile).getBytes("UTF-8");
String originalHex = DatatypeConverter.printHexBinary(originalBytes);

byte[] otsFile = Files.readAllBytes(fileData.get("otsFilePath"));
byte[] otsBytes = new String(otsFile).getBytes("UTF-8");
String otsHex = DatatypeConverter.printHexBinary(otsBytes);

// below is from the examples...

DetachedTimestampFile detached = DetachedTimestampFile.from( new OpSHA256(), originalFile );
DetachedTimestampFile detachedOts = DetachedTimestampFile.deserialize(ots);

HashMap<Chains, VerifyResult> result = OpenTimestamps.verify(detachedOts,detached);

And this the exception:

java.lang.NullPointerException: null
    at com.eternitywall.ots.Timestamp.doTagOrAttestation(Timestamp.java:101) ~[java-opentimestamps-1.16.jar:na]
    at com.eternitywall.ots.Timestamp.deserialize(Timestamp.java:89) ~[java-opentimestamps-1.16.jar:na]
    at com.eternitywall.ots.DetachedTimestampFile.deserialize(DetachedTimestampFile.java:107) ~[java-opentimestamps-1.16.jar:na]
    at com.eternitywall.ots.DetachedTimestampFile.deserialize(DetachedTimestampFile.java:120) ~[java-opentimestamps-1.16.jar:na]
    at com.fmr.ots.FileTimestampController.verifyDocument(FileTimestampController.java:110) ~[classes/:na]

Does anyone know how to correctly read the original file and ots file in order to correctly verify the file?

simbro
  • 3,372
  • 7
  • 34
  • 46
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Progman Nov 15 '18 at 13:22
  • Thanks Progman - though I don't see how it relates to my problem - the parameters I'm passing to the Opentimestamps class is not a null pointer. – simbro Nov 15 '18 at 15:27
  • Please edit your question to include a [MCVE](https://stackoverflow.com/help/mcve) which can be compiled and tested by others, which will throw the NullPointerException you get. – Progman Nov 15 '18 at 15:33

1 Answers1

0

Ots file can be read as follows

Path pathOts = Paths.get(otsfilename);
byte[] byteOts = Files.readAllBytes(pathOts);
DetachedTimestampFile detachedOts = DetachedTimestampFile.deserialize(byteOts);

The normal file can be read and converted to DetachedTimeStamp as,

File file = new File(originalfilename);
DetachedTimestampFile detached = DetachedTimestampFile.from(new OpSHA256(), file);

Finally the verify method can be called using the detached and detachedOts file

HashMap<Chains, VerifyResult> result = OpenTimestamps.verify(detachedOts,detached);
Rebekkal
  • 26
  • 3