Author: doogie
Date: Fri May 4 20:40:17 2012
New Revision: 1334166
URL:
http://svn.apache.org/viewvc?rev=1334166&view=revLog:
FEATURE: Add HashCrypt.digestHash64.
Modified:
ofbiz/trunk/framework/base/src/org/ofbiz/base/crypto/HashCrypt.java
Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/crypto/HashCrypt.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/crypto/HashCrypt.java?rev=1334166&r1=1334165&r2=1334166&view=diff==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/crypto/HashCrypt.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/crypto/HashCrypt.java Fri May 4 20:40:17 2012
@@ -180,6 +180,24 @@ public class HashCrypt {
}
}
+ public static String digestHash64(String hashType, byte[] bytes) {
+ if (hashType == null) {
+ hashType = "SHA";
+ }
+ try {
+ MessageDigest messagedigest = MessageDigest.getInstance(hashType);
+ messagedigest.update(bytes);
+ byte[] digestBytes = messagedigest.digest();
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("{").append(hashType).append("}");
+ sb.append(Base64.encodeBase64URLSafeString(digestBytes).replace('+', '.'));
+ return sb.toString();
+ } catch (NoSuchAlgorithmException e) {
+ throw new GeneralRuntimeException("Error while computing hash of type " + hashType, e);
+ }
+ }
+
/**
* @deprecated use cryptPassword
*/