把字符串数组转换为16进制字符串

  1. import java.security.MessageDigest;
  2.  
  3. public class StringUtil {
  4. public StringUtil() {
  5. super();
  6. }
  7.  
  8. public static String str;
  9. public static final String EMPTY_STRING = "";
  10. private final static String[] hexDigits = { "0", "1", "2", "3", "4", "5",
  11. "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" };
  12.  
  13. private static String byteToHexString(byte b) {
  14. int n = b;
  15. if (n < 0)
  16. n = 256 + n;
  17. int d1 = n / 16;
  18. int d2 = n % 16;
  19. return hexDigits[d1] + hexDigits[d2];
  20. }
  21.  
  22. /**
  23. * 转换字节数组为16进制字串
  24. * @param b 字节数组
  25. * @return 16进制字串
  26. */
  27. public static String byteArrayToHexString(byte[] b) {
  28. StringBuffer resultSb = new StringBuffer();
  29. for (int i = 0; i < b.length; i++) {
  30. resultSb.append(byteToHexString(b[i]));
  31. }
  32. return resultSb.toString();
  33. }
  34.  
  35. public static String MD5Encode(String origin) {
  36. String resultString = null;
  37. try {
  38. resultString = new String(origin);
  39. MessageDigest md = MessageDigest.getInstance("MD5");
  40. resultString = byteArrayToHexString(md.digest(resultString
  41. .getBytes()));
  42. } catch (Exception ex) {
  43. }
  44. return resultString;
  45. }
  46. }

java中把字节数组转换为16进制字符串的更多相关文章

  1. C#//字节数组转16进制字符串

    //字节数组转16进制字符串 private static string byteToHexStr(byte[] bytes,int length) { string returnStr = &quo ...

  2. BYTE数组与16进制字符串互转

    //字节数组转换为HEX 字符串const string Byte2HexString(const unsigned char* input, const int datasize) { ]; ; j ...

  3. java字节数组和16进制之间的转换

    /* * To change this template, choose Tools | Templates * and open the template in the editor. */ pac ...

  4. java标签(label)求16进制字符串的整数和 把一个整数转为4个16进制字符表示

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #4f76cb } p.p2 { margin: 0.0px 0. ...

  5. redis中get值显示为16进制字符串的解决方法

    Linux系统中,通过xshell登录redis,当根据某个key进行get取值时,取到的值为“\xc2\xed\xc0\xad\xcb\xb9\xbc\xd3”格式的十六进制字符串,原因是值中的中文 ...

  6. hex(x) 将整数x转换为16进制字符串

    >>> a = 122 >>> b = 344 >>> c = hex(a) >>> d = hex(b) >>&g ...

  7. java中 16进制字符串 与普通字符串 与 byte数组 之间的转化

    方法依赖commons-codec包  maven的引入方式如下 <dependency> <groupId>commons-codec</groupId> < ...

  8. Java中byte与16进制字符串的互相转换

    * Convert byte[] to hex string.这里我们可以将byte转换成int,然后利用Integer.toHexString(int)来转换成16进制字符串. * @param s ...

  9. [转]Java中byte与16进制字符串的互相转换

    Java中byte用二进制表示占用8位,而我们知道16进制的每个字符需要用4位二进制位来表示(23 + 22 + 21 + 20 = 15),所以我们就可以把每个byte转换成两个相应的16进制字符, ...

随机推荐

  1. 在网页中获取 facebook page 的内容

    参考 : http://www.ibm.com/developerworks/cn/opensource/os-cn-facebookapi/ 1.首先你要有 facebook page, 内容要公开 ...

  2. 用vlc SDK创建一个播放视频文件和RTSP流视频的Demo

    #include <stdio.h> #include <tchar.h> #include <time.h> #include <windows.h> ...

  3. Redis应用场景 及其数据对象 string hash list set sortedset

    原文地址:http://www.cnblogs.com/shanyou/archive/2012/09/04/2670972.html Redis开创了一种新的数据存储思路,使用Redis,我们不用在 ...

  4. SRM 601 DIV1

    A 枚举x , 然后对于确定的x , 最后总的apple数对应了唯一的orange数,因此问题转化为求apple的取值范围; apple的取值范围: max为每个bag取最多的apple , min为 ...

  5. You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.", PowmInsecureWarning

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAApcAAAB3CAIAAADZ1fxtAAAbFElEQVR4nO2dzbHDOo6FHY9S0WqqZt

  6. HDFS文件系统的操作

    package com.bank.utils; import java.io.BufferedInputStream;import java.io.BufferedOutputStream;impor ...

  7. SQL 查询某字段id为空(不为空)

    1 sql 查询某字段id为空 select *  from  表名 where  id  is   null  ; 2 sql 查询某字段id不为空 select * from   表名  wher ...

  8. Apache https 配置指南

    Windows Apache HTTPS配置创建下面3个目录: C:\Program Files\Apache Group\Apache2\conf\sslC:\Program Files\Apach ...

  9. (step4.3.1) hdu 1010(Tempter of the Bone——DFS)

    题目大意:输入三个整数N,M,T.在接下来的N行.M列会有一系列的字符.其中S表示起点,D表示终点. .表示路 . X表示墙...问狗能有在T秒时到达D.如果能输出YES, 否则输出NO 解题思路:D ...

  10. cocos2d-x 3.0 画图节点——Node

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...