public static String caculateCurrentBlockhash(BlockInfo blockInfo) throws IOException, IllegalAccessException, InvocationTargetException, InvalidArgumentException, InstantiationException, NoSuchMethodException, CryptoException, ClassNotFoundException {
CryptoSuite cryptoSuite = CryptoSuite.Factory.getCryptoSuite();
ByteArrayOutputStream s = new ByteArrayOutputStream();
DERSequenceGenerator seq = new DERSequenceGenerator(s);
seq.addObject(new ASN1Integer(blockInfo.getBlockNumber()));
seq.addObject(new DEROctetString(blockInfo.getPreviousHash()));
seq.addObject(new DEROctetString(blockInfo.getDataHash()));
seq.close();
byte[] hash = cryptoSuite.hash(s.toByteArray());
return Hex.encodeHexString(hash);
}
fabric区块中只包含了前一区块hash和datahash, 并没有当前区块hash , 不过查看fabric源码就可以仿照写出计算hash的代码, 上面是我仿照官方代码写的一段自己的计算hash工具,
觉得还可以的话, 顺手点个赞吧