zoukankan      html  css  js  c++  java
  • java工具方法

    仅记录所遇到并使用的工具方法。

    1.md5加密

     1 /**
     2  * 对传入的字符串数据进行MD5加密
     3  * @param source    字符串数据
     4  * @param code      字符编码
     5  * @return   加密以后的数据
     6  */
     7 public static String encrypt(String source, String code) {
     8         MessageDigest md = null;        
     9         byte[] bt = null;
    10         try {
    11             bt = source.getBytes(code);
    12             md = MessageDigest.getInstance("MD5");
    13             md.update(bt);
    14             return BytesHexTransform.bytesToHexString(md.digest()); 
    15         } catch (NoSuchAlgorithmException e) {
    16             logger.error("非法摘要算法", e);
    17             throw new RuntimeException(e);    
    18         }catch (UnsupportedEncodingException e1) {
    19             // TODO Auto-generated catch block
    20             e1.printStackTrace();
    21         }
    22         return null;
    23     }
     1 /**
     2  * 把字节数组转换成16进制字符串
     3  * @param bArray 传入的二进制数组
     4  * @return 16进制的字符串
     5  */
     6     public static String bytesToHexString(byte[] bArray) {
     7         StringBuffer sb = new StringBuffer(bArray.length);
     8         String sTemp;
     9         for (int i = 0; i < bArray.length; i++) {
    10             sTemp = Integer.toHexString(0xFF & bArray[i]);
    11             if (sTemp.length() < 2)
    12                 sb.append(0);
    13             sb.append(sTemp.toUpperCase());
    14         }
    15         return sb.toString();
    16     }

    未完待续。。。

  • 相关阅读:
    JMeter:全面的乱码解决方案
    代码静态扫描工具sonar
    jmeter接口测试
    MVC模式
    Android--HttpClient
    android SQLite使用SQLiteOpenHelper类对数据库进行操作
    反射
    列约束
    MVC的处理过程
    android项目中values中几个文件的作用
  • 原文地址:https://www.cnblogs.com/eric-fang/p/5026555.html
Copyright © 2011-2022 走看看