Opentimestamps - Java 尝试反序列化 OTS 文件时出现 NullPointerException
Opentimestamps - Java NullPointerException when trying to deserialize OTS file
当我尝试使用 Java 库验证时间戳时,我 运行 陷入 Java NullPointerException。
我正在按照 https://github.com/opentimestamps/java-opentimestamps
的自述文件中的示例进行操作
这是我的代码:
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);
这是个例外:
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]
有谁知道如何正确读取原文件和ots文件才能正确校验文件吗?
ots文件可以读取如下
Path pathOts = Paths.get(otsfilename);
byte[] byteOts = Files.readAllBytes(pathOts);
DetachedTimestampFile detachedOts = DetachedTimestampFile.deserialize(byteOts);
普通文件可以读取并转换为DetachedTimeStamp as,
File file = new File(originalfilename);
DetachedTimestampFile detached = DetachedTimestampFile.from(new OpSHA256(), file);
最后可以使用分离的和分离的Ots文件调用验证方法
HashMap<Chains, VerifyResult> result = OpenTimestamps.verify(detachedOts,detached);
当我尝试使用 Java 库验证时间戳时,我 运行 陷入 Java NullPointerException。
我正在按照 https://github.com/opentimestamps/java-opentimestamps
的自述文件中的示例进行操作这是我的代码:
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);
这是个例外:
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]
有谁知道如何正确读取原文件和ots文件才能正确校验文件吗?
ots文件可以读取如下
Path pathOts = Paths.get(otsfilename);
byte[] byteOts = Files.readAllBytes(pathOts);
DetachedTimestampFile detachedOts = DetachedTimestampFile.deserialize(byteOts);
普通文件可以读取并转换为DetachedTimeStamp as,
File file = new File(originalfilename);
DetachedTimestampFile detached = DetachedTimestampFile.from(new OpSHA256(), file);
最后可以使用分离的和分离的Ots文件调用验证方法
HashMap<Chains, VerifyResult> result = OpenTimestamps.verify(detachedOts,detached);