-        ByteArrayOutputStream md5 = new ByteArrayOutputStream();
-        InputStream documentInputStream = new TeeInputStream(resourceDocument.getStream(), md5);
+
+        MessageDigest md = null;
+        try {
+            md = MessageDigest.getInstance("md5");
+        } catch (NoSuchAlgorithmException e) {
+            log.error(e.getMessage());
+            throw new RuntimeException(e);
+        }
+        InputStream documentInputStream = new DigestInputStream(resourceDocument.getStream(), md);
         org.jdom.Document jdomDocument = builder.build(documentInputStream);
         IOUtils.closeQuietly(documentInputStream);
 
-        String sign = SecurityUtil.getMD5Hex(md5.toByteArray());
+        final String sign = SecurityUtil.byteArrayToHex(md.digest());

Since we already have methods for getting md5hex from various input (string, byte array) wouldn't it make more sense to have such code in there rather then having everyone who needs to calculate it on a stream to do the same again and again? ... Even in your code you have to do it 2 times more below the code I've pasted above.

Change By: Jan Haderka (23/Apr/13 3:40 PM)
Resolution: Fixed
Status: Resolved Reopened
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira



----------------------------------------------------------------
For list details, see: http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to