SHA-256 加密

    public static void main(String[] args) {
            String strSrc = "123456";
            byte[] bt = strSrc.getBytes();
            MessageDigest md;
            try {
                md = MessageDigest.getInstance("SHA-256");
            } catch (NoSuchAlgorithmException e) {
                throw new IllegalStateException("服务器不支持SHA-256加密算法");
            }
            md.update(bt);
            StringBuffer des = new StringBuffer();
            for (byte b : md.digest()) {
                String dd = String.format("%02X", b);
                des.append(dd);
            }
            System.out.println(des.toString());
    }

 

posted @ 2017-12-04 10:58  RealWorld♂  阅读(265)  评论(0编辑  收藏  举报