下面两个都是在生成sign签名时候用到的方式,有什么区别?
第一种:
import org.apache.commons.codec.digest.DigestUtils;String sign = DigestUtils.md5Hex(string);
第二种:
方法片段:import java.security.MessageDigest;try { byte[] array = computeHash(params); StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < array.length; i++) { byte b = array[i]; String text = Integer.toHexString(b & 0xFF); if (text.length() == 1) { stringBuilder.append("0"); } stringBuilder.append(text); } return stringBuilder.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); }============================public static byte[] computeHash(String input) throws NoSuchAlgorithmException { MessageDigest digest = MessageDigest.getInstance("MD5"); digest.reset(); byte[] utf8bytes = null; try { utf8bytes = input.getBytes("UTF-8"); // digest.update(utf8bytes); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return digest.digest(utf8bytes); }
对比一下两种的区别