incubator-amber-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r1384824 - /incubator/amber/trunk/oauth-2.0/authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/MD5Generator.java
Date Fri, 14 Sep 2012 15:36:13 GMT
Author: rfeng
Date: Fri Sep 14 15:36:13 2012
New Revision: 1384824

URL: http://svn.apache.org/viewvc?rev=1384824&view=rev
Log:
Fix for https://issues.apache.org/jira/browse/AMBER-60

Modified:
    incubator/amber/trunk/oauth-2.0/authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/MD5Generator.java

Modified: incubator/amber/trunk/oauth-2.0/authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/MD5Generator.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/MD5Generator.java?rev=1384824&r1=1384823&r2=1384824&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/MD5Generator.java
(original)
+++ incubator/amber/trunk/oauth-2.0/authzserver/src/main/java/org/apache/amber/oauth2/as/issuer/MD5Generator.java
Fri Sep 14 15:36:13 2012
@@ -40,6 +40,20 @@ public class MD5Generator implements Val
         return generateValue(UUID.randomUUID().toString());
     }
 
+    private static final char[] hexCode = "0123456789abcdef".toCharArray();
+
+    public static String toHexString(byte[] data) {
+        if(data == null) {
+            return null;
+        }
+        StringBuilder r = new StringBuilder(data.length*2);
+        for ( byte b : data) {
+            r.append(hexCode[(b >> 4) & 0xF]);
+            r.append(hexCode[(b & 0xF)]);
+        }
+        return r.toString();
+    }
+
     @Override
     public String generateValue(String param) throws OAuthSystemException {
         try {
@@ -47,12 +61,7 @@ public class MD5Generator implements Val
             algorithm.reset();
             algorithm.update(param.getBytes());
             byte[] messageDigest = algorithm.digest();
-            StringBuffer hexString = new StringBuffer();
-            for (int i = 0; i < messageDigest.length; i++) {
-                hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
-            }
-
-            return hexString.toString();
+            return toHexString(messageDigest);
         } catch (Exception e) {
             throw new OAuthSystemException("OAuth Token cannot be generated.", e);
         }



Mime
View raw message