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