android 对字符串升序排序后,进行sha1 加密

android 对字符串升序排序后,进行sha1 加密,第1张

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;
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/720807.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-25
下一篇 2022-04-25

发表评论

登录后才能评论

评论列表(0条)

保存