1 import java
.security
.*;
5 // gnu-crypto/source/gnu/testlet/gnu/crypto/hash/TestOfSha160.java
7 public static void main(String
[] argv
) {
10 md
= MessageDigest
.getInstance("SHA-1");
11 } catch (Exception e
) {
14 md
.update("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq".getBytes(), 0, 56);
15 String exp
= "84983E441C3BD26EBAAE4AA1F95129E5E54670F1";
16 String result
= toString(md
.digest());
17 System
.out
.println(exp
);
18 System
.out
.println(result
);
19 if (!exp
.equals(result
))
20 System
.out
.println("NOT EQUAL!");
24 public static String
toString(byte[] ba
) {
25 return toString(ba
, 0, ba
.length
);
27 public static final String
toString(byte[] ba
, int offset
, int length
) {
28 char[] buf
= new char[length
* 2];
29 for (int i
= 0, j
= 0, k
; i
< length
; ) {
31 buf
[j
++] = HEX_DIGITS
[(k
>>> 4) & 0x0F];
32 buf
[j
++] = HEX_DIGITS
[ k
& 0x0F];
34 return new String(buf
);
37 private static final char[] HEX_DIGITS
= "0123456789ABCDEF".toCharArray();