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