public static void jiami(){
String[] arr = {"", "", ""};//排序
Arrays.sort(arr);
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < arr.length; i++) {
buffer.append(arr[i]);
}
String aa = SHA1Util.getSHA(buffer.toString());
Log.d("签名加密结束", "" + aa);
}
package org.cocos2dx.javascript;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class SHA1Util {
public static String getSHA(String info) {
byte[] bytesSHA = null;
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
messageDigest.update(info.getBytes());
bytesSHA = messageDigest.digest();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
String strSHA = byteToHex(bytesSHA);
return strSHA;
}
private static String byteToHex(byte[] bytes) {
String hs = "";
String temp;
for (byte b : bytes) {
temp = (Integer.toHexString(b & 0XFF));
if (temp.length() == 1) {
hs = hs + "0" + temp;
} else {
hs = hs + temp;
}
}
return hs;
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)