14
14
15
15
package org .casbin .jcasbin .util ;
16
16
17
- import com .google .common .hash .HashCode ;
18
- import com .google .common .hash .HashFunction ;
19
- import com .google .common .hash .Hashing ;
20
17
import org .apache .commons .csv .CSVFormat ;
21
18
import org .apache .commons .csv .CSVParser ;
22
19
import org .apache .commons .csv .CSVRecord ;
25
22
26
23
import java .io .IOException ;
27
24
import java .io .StringReader ;
28
- import java .nio .charset .Charset ;
25
+ import java .nio .charset .StandardCharsets ;
26
+ import java .security .MessageDigest ;
27
+ import java .security .NoSuchAlgorithmException ;
29
28
import java .util .ArrayList ;
30
29
import java .util .Collections ;
31
30
import java .util .List ;
@@ -42,8 +41,7 @@ public class Util {
42
41
43
42
private static Logger LOGGER = LoggerFactory .getLogger ("org.casbin.jcasbin" );
44
43
45
- private static HashFunction hf = Hashing .md5 ();
46
- private static Charset defaultCharset = Charset .forName ("UTF-8" );
44
+ private static final String md5AlgorithmName = "MD5" ;
47
45
48
46
/**
49
47
* logPrint prints the log.
@@ -290,7 +288,14 @@ public static String replaceEval(String s, String replacement) {
290
288
}
291
289
292
290
public static String md5 (String data ) {
293
- HashCode hash = hf .newHasher ().putString (data , defaultCharset ).hash ();
294
- return hash .toString ();
291
+ return new String (getDigest (md5AlgorithmName ).digest (data .getBytes (StandardCharsets .UTF_8 )));
292
+ }
293
+
294
+ private static MessageDigest getDigest (String algorithm ) {
295
+ try {
296
+ return MessageDigest .getInstance (algorithm );
297
+ } catch (NoSuchAlgorithmException e ) {
298
+ throw new IllegalArgumentException (e );
299
+ }
295
300
}
296
301
}
0 commit comments