106
|
1 package christie.blockchain;
|
|
2
|
|
3 import org.bouncycastle.crypto.digests.*;
|
|
4
|
|
5
|
|
6 public class HashUtil {
|
|
7 public byte[] sha256(byte[] input) {
|
|
8 SHA256Digest digest = new SHA256Digest();
|
|
9 byte[] resBuf = new byte[digest.getDigestSize()];
|
|
10 if(input != null) {
|
|
11 digest.update(input, 0, input.length);
|
|
12 digest.doFinal(resBuf, 0);
|
|
13 }else{
|
|
14 throw new NullPointerException("Can't sha256 input is null.");
|
|
15 }
|
|
16 return resBuf;
|
|
17
|
|
18 }
|
|
19
|
|
20 public byte[] sha3(byte[] input){
|
|
21 SHA3Digest digest = new SHA3Digest();
|
|
22 byte[] resBuf = new byte[digest.getDigestSize()];
|
|
23 if(input != null) {
|
|
24 digest.update(input, 0, input.length);
|
|
25 digest.doFinal(resBuf, 0);
|
|
26 }else{
|
|
27 throw new NullPointerException("Can't sha3 input is null.");
|
|
28 }
|
|
29 return resBuf;
|
|
30
|
|
31 }
|
|
32
|
|
33 public byte[] ripemd160(byte[] input){
|
|
34 RIPEMD160Digest digest = new RIPEMD160Digest();
|
|
35 byte[] resBuf = new byte[digest.getDigestSize()];
|
|
36 if(input != null) {
|
|
37 digest.update(input, 0, input.length);
|
|
38 digest.doFinal(resBuf, 0);
|
|
39 }else{
|
|
40 throw new NullPointerException("Can't ripemd160 input is null.");
|
|
41 }
|
|
42 return resBuf;
|
|
43 }
|
|
44
|
110
|
45
|
|
46
|
106
|
47 }
|