Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 1 | package aQute.libg.cryptography; |
| 2 | |
| 3 | import java.io.*; |
| 4 | import java.security.*; |
| 5 | |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 6 | public class MD5 extends Digest { |
Stuart McCulloch | 4482c70 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 7 | public final static String ALGORITHM = "MD5"; |
| 8 | |
| 9 | public static Digester<MD5> getDigester(OutputStream... out) throws Exception { |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 10 | return new Digester<MD5>(MessageDigest.getInstance(ALGORITHM), out) { |
Stuart McCulloch | 4482c70 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 11 | |
| 12 | @Override |
| 13 | public MD5 digest() throws Exception { |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 14 | return new MD5(md.digest()); |
| 15 | } |
| 16 | |
Stuart McCulloch | 4482c70 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 17 | @Override |
| 18 | public MD5 digest(byte[] bytes) { |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 19 | return new MD5(bytes); |
| 20 | } |
Stuart McCulloch | 4482c70 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 21 | |
| 22 | @Override |
| 23 | public String getAlgorithm() { |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 24 | return ALGORITHM; |
| 25 | } |
| 26 | }; |
| 27 | } |
Stuart McCulloch | 4482c70 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 28 | |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 29 | public MD5(byte[] digest) { |
Stuart McCulloch | 4482c70 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 30 | super(digest, 16); |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Stuart McCulloch | 4482c70 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 33 | @Override |
| 34 | public String getAlgorithm() { |
| 35 | return ALGORITHM; |
| 36 | } |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 37 | |
| 38 | } |