aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorferbas <ferbas@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2009-10-27 11:15:45 +0000
committerferbas <ferbas@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2009-10-27 11:15:45 +0000
commit6039c1ffbf2cbdb7abfb9984778829ac9cc5be6d (patch)
tree8b8aaef873d99e802349b5c7c8622cca8509f314
parentc05dcddaf830c64559bc18a8cade2e4bf25a1fd5 (diff)
downloadpdf-as-3-6039c1ffbf2cbdb7abfb9984778829ac9cc5be6d.tar.gz
pdf-as-3-6039c1ffbf2cbdb7abfb9984778829ac9cc5be6d.tar.bz2
pdf-as-3-6039c1ffbf2cbdb7abfb9984778829ac9cc5be6d.zip
parameterized codinghelper with hash method
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@366 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/tools/CodingHelper.java28
1 files changed, 19 insertions, 9 deletions
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);
}
/**