Stuart McCulloch | bb01437 | 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 | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 6 | public class SHA256 extends Digest { |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 7 | public final static String ALGORITHM = "SHA256"; |
| 8 | |
| 9 | public static Digester<SHA256> getDigester(OutputStream... out) throws NoSuchAlgorithmException { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 10 | MessageDigest md = MessageDigest.getInstance(ALGORITHM); |
| 11 | return new Digester<SHA256>(md, out) { |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 12 | @Override |
| 13 | public SHA256 digest() throws Exception { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 14 | return new SHA256(md.digest()); |
| 15 | } |
| 16 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 17 | @Override |
| 18 | public SHA256 digest(byte[] bytes) { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 19 | return new SHA256(bytes); |
| 20 | } |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 21 | |
| 22 | @Override |
| 23 | public String getAlgorithm() { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 24 | return ALGORITHM; |
| 25 | } |
| 26 | }; |
| 27 | } |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 28 | |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 29 | public SHA256(byte[] b) { |
| 30 | super(b, 32); |
| 31 | } |
| 32 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 33 | @Override |
| 34 | public String getAlgorithm() { |
| 35 | return ALGORITHM; |
| 36 | } |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 37 | |
| 38 | } |