-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmd.java
More file actions
37 lines (30 loc) · 1 KB
/
md.java
File metadata and controls
37 lines (30 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.zulip.android.util;
import android.util.Log;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* Gravatar example from http://en.gravatar.com/site/implement/images/java/
*/
public class MD5Util {
private static final String TAG = "MD5Util";
private MD5Util() {
}
private static String hex(byte[] array) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < array.length; ++i) {
sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(
1, 3));
}
return sb.toString();
}
public static String md5Hex(String message) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
return hex(md.digest(message.getBytes("CP1252")));
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
Log.e(TAG, e.getMessage(), e);
}
return null;
}
}