Java Code Examples for org.apache.commons.codec.digest.DigestUtils#getSha256Digest()
The following examples show how to use
org.apache.commons.codec.digest.DigestUtils#getSha256Digest() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Block.java From blockchain with MIT License | 5 votes |
/** * Calculate new hash based on blocks contents * @param block 区块 * @return */ public static String calculateHash(Block block) { String record = block.getIndex() + block.getTimestamp() + block.getNonce() + block.getPrevHash()+block.getMerkleRoot(); MessageDigest digest = DigestUtils.getSha256Digest(); byte[] hash = digest.digest(StringUtils.getBytesUtf8(record)); return Hex.encodeHexString(hash); }
Example 2
Source File: CommonUtils.java From blockchain with MIT License | 4 votes |
public static String applySha256(String input) { MessageDigest digest = DigestUtils.getSha256Digest(); byte[] hash = digest.digest(StringUtils.getBytesUtf8(input)); return Hex.encodeHexString(hash); }
Example 3
Source File: BlockUtils.java From blockchain with MIT License | 3 votes |
/** * 计算区块的hash值 * * @param block * 区块 * @return */ public static String calculateHash(Block block) { String record = (block.getIndex()) + block.getTimestamp() + (block.getVac()) + block.getPrevHash(); MessageDigest digest = DigestUtils.getSha256Digest(); byte[] hash = digest.digest(StringUtils.getBytesUtf8(record)); return Hex.encodeHexString(hash); }
Example 4
Source File: SparkWeb.java From blockchain with MIT License | 3 votes |
/** * 计算区块的hash值 * * @param block * 区块 * @return */ public static String calculateHash(Block block) { String record = (block.getIndex()) + block.getTimestamp() + (block.getVac()) + block.getPrevHash(); MessageDigest digest = DigestUtils.getSha256Digest(); byte[] hash = digest.digest(StringUtils.getBytesUtf8(record)); return Hex.encodeHexString(hash); }
Example 5
Source File: BlockUtils.java From blockchain with MIT License | 3 votes |
/** * 计算区块的hash值 * * @param block * 区块 * @return */ public static String calculateHash(Block block) { String record = (block.getIndex()) + block.getTimestamp() + (block.getVac()) + block.getPrevHash(); MessageDigest digest = DigestUtils.getSha256Digest(); byte[] hash = digest.digest(StringUtils.getBytesUtf8(record)); return Hex.encodeHexString(hash); }
Example 6
Source File: SparkWebWithPOW.java From blockchain with MIT License | 3 votes |
/** * 计算区块的hash值 * * @param block * 区块 * @return */ public static String calculateHash(Block block) { String record = block.getIndex() + block.getTimestamp() + (block.getVac()) + block.getPrevHash()+block.getNonce(); MessageDigest digest = DigestUtils.getSha256Digest(); byte[] hash = digest.digest(StringUtils.getBytesUtf8(record)); return Hex.encodeHexString(hash); }