zoukankan      html  css  js  c++  java
  • MD5加密(Android里和Java SE里是一样的)

     1 package com.gnnuit.mobilesafe.util;
     2 
     3 import java.security.MessageDigest;
     4 import java.security.NoSuchAlgorithmException;
     5 
     6 public class MD5Encoder {
     7     /**
     8      * MD5加密
     9      * 
    10      * @param pwd要加密的数据
    11      * @return 加密后的数据
    12      * @throws Exception
    13      */
    14     public static String encode(String pwd) {
    15         try {
    16             MessageDigest digest = MessageDigest.getInstance("MD5");
    17             byte[] bytes = digest.digest(pwd.getBytes());
    18             StringBuffer sb = new StringBuffer();
    19             for (int i = 0; i < bytes.length; i++) {
    20                 String s = Integer.toHexString(0xff & bytes[i]);
    21                 if (s.length() == 1) {
    22                     sb.append("0" + s);
    23                 } else {
    24                     sb.append(s);
    25                 }
    26             }
    27             return sb.toString();
    28         } catch (NoSuchAlgorithmException e) {
    29             // TODO Auto-generated catch block
    30             e.printStackTrace();
    31             throw new RuntimeException("永远不会发生");
    32         }
    33     }
    34 }
  • 相关阅读:
    软件课程设计(3)
    软件课程设计(2)
    软件课程设计(1)
    继往开来第五天
    勤勤恳恳第四天
    撸起袖子第三天
    厉兵秣马第二天
    项目初定第一天
    Magic-Club第五天
    Magic-Club第四天
  • 原文地址:https://www.cnblogs.com/FlySheep/p/3494815.html
Copyright © 2011-2022 走看看