此文章是vip文章,如何查看?  

1,点击链接获取密钥 http://nicethemes.cn/product/view29882.html

2,在下方输入文章查看密钥即可立即查看当前vip文章


Android 实现SHA1加密算法代码

  • 时间:
  • 浏览:
  • 来源:互联网

实现SHA1加密代码

    public static String getSecurityAppKey() {
                return encryptToSHA(RequestTools.AppId + "UZ" +
                        RequestTools.AppKey + "UZ" + System.currentTimeMillis()) +
                        "." + System.currentTimeMillis();
            }

    public static String encryptToSHA(String info) {
        byte[] digesta = null;
        try {
            MessageDigest alga = MessageDigest.getInstance("SHA-1");
            alga.update(info.getBytes());
            digesta = alga.digest();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        String rs = byte2hex(digesta);
        return rs;
    }

    public static String byte2hex(byte[] b) {
        String hs = "";
        String stmp = "";
        for (int n = 0; n < b.length; n++) {
            stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
            if (stmp.length() == 1) {
                hs = hs + "0" + stmp;
            } else {
                hs = hs + stmp;
            }
        }
        return hs;
    }

使用方法按照getSecurityAppKey方法使用,将要加密的字串写到encryptToSHA中即可!

本文链接http://element-ui.cn/news/show-577118.aspx