Store data model CND files
[lgpl/argeo-commons.git] / base / runtime / org.argeo.util / src / main / java / org / argeo / util / security / DigestUtils.java
index ade5b1e0112bd0afc8295bc147d86fbde7907662..b6aae6fd4988925b62da9d060bc9958f93d91c3e 100644 (file)
@@ -33,6 +33,19 @@ public class DigestUtils {
        // TODO: make it writable
        private final static Integer byteBufferCapacity = 100 * 1024;// 100 KB
 
+       public static String digest(String algorithm, byte[] bytes) {
+               try {
+                       MessageDigest digest = MessageDigest.getInstance(algorithm);
+                       digest.update(bytes);
+                       byte[] checksum = digest.digest();
+                       String res = StreamUtils.encodeHexString(checksum);
+                       return res;
+               } catch (Exception e) {
+                       throw new ArgeoException("Cannot digest with algorithm "
+                                       + algorithm, e);
+               }
+       }
+
        public static String digest(String algorithm, InputStream in) {
                try {
                        MessageDigest digest = MessageDigest.getInstance(algorithm);