标签:
1 public static String signatureSHA1(Map<String, String> map) { 2 3 Set<String> keySet = map.keySet(); 4 5 String[] str = new String[map.size()]; 6 7 StringBuilder tmp = new StringBuilder(); 8 9 // 进行字典排序 10 11 str = keySet.toArray(str); 12 13 Arrays.sort(str); 14 15 for (int i = 0; i < str.length; i++) { 16 17 String t = str[i] + "=" + map.get(str[i]) + "&"; 18 19 tmp.append(t); 20 21 } 22 23 String tosend = tmp.toString().substring(0, tmp.length() - 1); 24 25 MessageDigest md = null; 26 27 byte[] bytes = null; 28 29 try { 30 31 md = MessageDigest.getInstance("SHA-1"); 32 33 bytes = md.digest(tosend.getBytes("utf-8")); 34 35 } catch (Exception e) { 36 37 e.printStackTrace(); 38 39 } 40 41 String singe = byteToStr(bytes); 42 43 return singe.toLowerCase(); 44 45 }
标签:
原文地址:http://www.cnblogs.com/Seanit/p/5324401.html