-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob1
32 lines (24 loc) · 916 Bytes
/
job1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/********* Block *********/
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* Created by hosang on 2017. 12. 2..
*/
public class Block {
private int blockSize; // Ignore for now.
private BlockHeader blockHeader;
private int transactionCount; // Ignore for now.
private Object[] transactions;
public Block(BlockHeader blockHeader, Object[] transactions){
this.blockHeader = blockHeader;
this.transactions = transactions;
}
public String getBlockHash() throws NoSuchAlgorithmException {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
// Hash twice - Not a K-pop girl group.
byte[] blockHash = messageDigest.digest(blockHeader.toByteArray());
blockHash = messageDigest.digest(blockHash);
return new String(blockHash,0,blockHash.length);
}
}