Skip to content

Commit 1e76f40

Browse files
committed
添加签名文件
1 parent 1eb97bf commit 1e76f40

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.qcloud.weapp;
2+
3+
import java.security.MessageDigest;
4+
5+
public class Hash {
6+
7+
private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5',
8+
'6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
9+
10+
public static String compute(String str, String algorithm) {
11+
if (str == null) {
12+
return null;
13+
}
14+
try {
15+
MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
16+
messageDigest.update(str.getBytes());
17+
return getHashText(messageDigest.digest());
18+
} catch (Exception e) {
19+
throw new RuntimeException(e);
20+
}
21+
22+
}
23+
24+
public static String sha1(String str) {
25+
return compute(str, "SHA1");
26+
}
27+
28+
public static String md5(String str) {
29+
return compute(str, "MD5");
30+
}
31+
32+
private static String getHashText(byte[] bytes) {
33+
int len = bytes.length;
34+
StringBuilder buf = new StringBuilder(len * 2);
35+
for (int j = 0; j < len; j++) {
36+
buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);
37+
buf.append(HEX_DIGITS[bytes[j] & 0x0f]);
38+
}
39+
return buf.toString();
40+
}
41+
}

com.qcloud.weapp.sdk/src/com/qcloud/weapp/tunnel/TunnelAPI.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.qcloud.weapp.tunnel;
22

3-
import java.io.StringWriter;
4-
import java.io.UnsupportedEncodingException;
5-
63
import org.json.JSONArray;
74
import org.json.JSONException;
85
import org.json.JSONObject;

0 commit comments

Comments
 (0)