|
1.import java.io.UnsupportedEncodingException;
2.import java.security.MessageDigest;
3.import java.security.NoSuchAlgorithmException;
4.import java.util.HashMap;
5.import java.util.Map;
6.
7.
8.public class Util {
9. private static Map<String, Integer> map = new HashMap<String, Integer>();
10.
11. private static int getIncByName(String keyName){
12. if(map.size() == 0){
13. map.put("97ba558178f22af9", 1);
14. map.put("8a57faa3ff0c2cd0", 2);
15. map.put("b05395426617a666", 3);
16. map.put("8054b38ece415448", 4);
17. map.put("5a0815d2500be4c3", 5);
18. map.put("cb47e040c444bb13", 6);
19. map.put("4f0b466d4e838204", 7);
20. map.put("9bb033dd03a03a21", 8);
21. map.put("a548d6aefbeb32e0", 9);
22. map.put("c156d1c03531d5f6", 10);
23. }
24. if(map.containsKey(keyName)){
25. int v = map.get(keyName);
26. return v;
27. }
28. throw new RuntimeException("无法找到keyName:"+keyName);
29. }
30.
31. /**
32. * 取到sig
33. */
34. public static String getSig(String key, String keyName){
35. int inc = getIncByName(keyName);
36.
37. String _local2 = Md5(key);
38. System.out.println(_local2);
39. _local2 = Md5(_local2);
40. _local2 = _local2.substring(1, 7);
41. _local2 = Md5(_local2);
42. String p1 = _local2;
43.
44.
45. String a = p1.substring(0, 6);
46. int v = Integer.parseInt(a, 16);
47. v = v + inc;
48. System.out.println(v);
49. a = Md5(v+"");
50. return a;
51. }
52.
53. public static String Md5(String str){
54. MessageDigest messageDigest = null;
55.
56. try {
57. messageDigest = MessageDigest.getInstance("MD5");
58.
59. messageDigest.reset();
60.
61. messageDigest.update(str.getBytes("UTF-8"));
62. } catch (NoSuchAlgorithmException e) {
63. System.out.println("NoSuchAlgorithmException caught!");
64. System.exit(-1);
65. } catch (UnsupportedEncodingException e) {
66. e.printStackTrace();
67. }
68.
69. byte[] byteArray = messageDigest.digest();
70.
71.
72. StringBuffer md5StrBuff = new StringBuffer();
73.
74. for (int i = 0; i < byteArray.length; i++) {
75. if (Integer.toHexString(0xFF & byteArray[i]).length() == 1)
76. md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i]));
77. else
78. md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
79. }
80.
81. return md5StrBuff.toString();
82.
83. }
84.}
这段java代码 改成au3 如何改啊?看不懂java |
|