blob: d0a486cbd41ae9acfe29db4d25c780cd598dedf2 [file] [log] [blame]
Stuart McCullochbb014372012-06-07 21:57:32 +00001package aQute.libg.cryptography;
2
3import java.io.*;
4import java.security.*;
5
Stuart McCullochbb014372012-06-07 21:57:32 +00006public class SHA1 extends Digest {
Stuart McCulloch2286f232012-06-15 13:27:53 +00007 public final static String ALGORITHM = "SHA1";
8
9 public static Digester<SHA1> getDigester(OutputStream... out) throws NoSuchAlgorithmException {
Stuart McCullochbb014372012-06-07 21:57:32 +000010 MessageDigest md = MessageDigest.getInstance(ALGORITHM);
11 return new Digester<SHA1>(md, out) {
Stuart McCulloch2286f232012-06-15 13:27:53 +000012 @Override
13 public SHA1 digest() throws Exception {
Stuart McCullochbb014372012-06-07 21:57:32 +000014 return new SHA1(md.digest());
15 }
16
Stuart McCulloch2286f232012-06-15 13:27:53 +000017 @Override
18 public SHA1 digest(byte[] bytes) {
Stuart McCullochbb014372012-06-07 21:57:32 +000019 return new SHA1(bytes);
20 }
Stuart McCulloch2286f232012-06-15 13:27:53 +000021
22 @Override
23 public String getAlgorithm() {
Stuart McCullochbb014372012-06-07 21:57:32 +000024 return ALGORITHM;
25 }
26 };
27 }
Stuart McCulloch2286f232012-06-15 13:27:53 +000028
Stuart McCullochbb014372012-06-07 21:57:32 +000029 public SHA1(byte[] b) {
30 super(b, 20);
31 }
32
Stuart McCulloch2286f232012-06-15 13:27:53 +000033 @Override
34 public String getAlgorithm() {
35 return ALGORITHM;
36 }
Stuart McCullochbb014372012-06-07 21:57:32 +000037
38}