在hash加密的过程,执行所有必需的步骤,确保不会削弱所生成hash值的强度。

    1. MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
    2. messageDigest.update(inputText.getBytes());
    3. byte byteBuffer[] = messageDigest.digest();
    4. StringBuilder strHexString = new StringBuilder();
    5. for (int i = 0; i < byteBuffer.length; i++) {
    6. String hex = Integer.toHexString(0xff & byteBuffer[i]);
    7. if (hex.length() == 1) {
    8. strHexString.append('0');
    9. }
    10. strHexString.append(hex);
    11. }
    12. strResult = strHexString.toString();