wemall-mobile是基于WeMall的android app商城,只需要在原商城目录下上传接口文件即可完成服务端的配置,客户端可定制修改。本文分享android开发MD5加密工具类主要代码,供技术员参考学习。

点击(此处)折叠或打开

  1. package com.gzcivil.utils;

  2. import java.io.UnsupportedEncodingException;
  3. import java.security.MessageDigest;
  4. import java.security.NoSuchAlgorithmException;

  5. public class MD5Tool {

  6.     public static String md5(String string) {
  7.         byte[] hash;
  8.         try {
  9.             hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8"));
  10.         } catch (NoSuchAlgorithmException e) {
  11.             throw new RuntimeException("Huh, MD5 should be supported?", e);
  12.         } catch (UnsupportedEncodingException e) {
  13.             throw new RuntimeException("Huh, UTF-8 should be supported?", e);
  14.         }

  15.         StringBuilder hex = new StringBuilder(hash.length * 2);
  16.         for (byte b : hash) {
  17.             if ((b & 0xFF) < 0x10)
  18.                 hex.append("0");
  19.             hex.append(Integer.toHexString(b & 0xFF));
  20.         }
  21.         return hex.toString();
  22.     }

  23.     public static String encrypt(String data) {
  24.         if (data == null)
  25.             data = "";
  26.         byte[] btRet = null;
  27.         try {
  28.             btRet = _encrypt(data.getBytes("utf-8"));
  29.         } catch (UnsupportedEncodingException e) {
  30.             e.printStackTrace();
  31.         }
  32.         if (btRet == null)
  33.             return null;
  34.         return BinStr.byte2str(btRet).toLowerCase();
  35.     }

  36.     /**
  37.      * 加密MD5
  38.      *
  39.      * @param content
  40.      * 需要加密的内容
  41.      * @param password
  42.      * 加密密码
  43.      * @return
  44.      */
  45.     private static byte[] _encrypt(byte[] btData) {
  46.         try {
  47.             // 获得MD5摘要算法的 MessageDigest 对象
  48.             MessageDigest mdInst = MessageDigest.getInstance("MD5");
  49.             // 使用指定的字节更新摘要
  50.             mdInst.update(btData);
  51.             // 获得密文
  52.             return mdInst.digest();
  53.         } catch (Exception e) {
  54.             e.printStackTrace();
  55.             return null;
  56.         }
  57.     }
  58.     
  59.      
  60. }

原文详情地址:http://git.oschina.net/einsqing/wemall-mobile

wemall-mobile商城详情地址:http://www.koahub.com/home/product/56

wemall官网地址:http://www.wemallshop.com

WeMall - 开源微商城 微信商城 商城源码 分销商城 b2b2c商城系统

wemall app商城源码android开发MD5加密工具类-LMLPHP

10-30 02:01