From 6039c1ffbf2cbdb7abfb9984778829ac9cc5be6d Mon Sep 17 00:00:00 2001 From: ferbas Date: Tue, 27 Oct 2009 11:15:45 +0000 Subject: parameterized codinghelper with hash method git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@366 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../wag/egov/egiz/tools/CodingHelper.java | 28 +++++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'src/main/java/at/knowcenter/wag/egov') diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/tools/CodingHelper.java b/src/main/java/at/knowcenter/wag/egov/egiz/tools/CodingHelper.java index fe0cfcb..ce46e68 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/tools/CodingHelper.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/tools/CodingHelper.java @@ -197,22 +197,24 @@ public class CodingHelper } } + // dferbas /** - * This method builds an SHA-1 hash value of a given byte array. + * This method builds an hash value of a given byte array. * * @param data * the byte array to build the hash value for + * @param hashAlg hash algorithm for {@link MessageDigest} e.g. "SHA-1" * @return the calculated hash value as a byte array * @see MessageDigest */ - public static byte[] buildDigest(byte[] data) - { - MessageDigest sha_1 = null; + public static byte[] buildDigest(byte[] data, String hashAlg) + { + MessageDigest digester = null; try { - sha_1 = MessageDigest.getInstance("SHA-1"); - sha_1.update(data); - return sha_1.digest(); + digester = MessageDigest.getInstance(hashAlg); + digester.update(data); + return digester.digest(); } catch (NoSuchAlgorithmException e) { @@ -220,11 +222,19 @@ public class CodingHelper } } - public static byte[] buildDigest(DataSource input) throws IOException + // dferbas + /** + * This method builds an hash value of a given byte array. + * @param input + * @param hashAlg hashAlg hash algorithm for {@link MessageDigest} e.g. "SHA-1" + * @return the calculated hash value as a byte array + * @throws IOException + */ + public static byte[] buildDigest(DataSource input, String hashAlg) throws IOException { // PERF: digesting needs data source. byte [] data = DataSourceHelper.convertDataSourceToByteArray(input); - return buildDigest(data); + return buildDigest(data, hashAlg); } /** -- cgit v1.2.3