/**

* 将字符串转成16 位MD5值





* @param string


* @return


*/


public static String MD5(String string) {


byte[] hash;


try {


hash = MessageDigest.getInstance("MD5").digest(


string.getBytes("UTF-8"));


} catch (NoSuchAlgorithmException e) {


e.printStackTrace();


return null;


} catch (UnsupportedEncodingException e) {


e.printStackTrace();


return null;


}

StringBuilder hex = new StringBuilder(hash.length * 2);


for (byte b : hash) {


if ((b & 0xFF) < 0x10)


hex.append("0");


hex.append(Integer.toHexString(b & 0xFF));

}

return hex.toString();// 32位

return hex.toString().toString().substring(8, 24);// 16位


}

Android String 转 MD5的更多相关文章

  1. Android数据加密之MD5加密

    前言: 项目中无论是密码的存储或者说判断文件是否是同一文件,都会用到MD5算法,今天来总结一下MD5加密算法. 什么是MD5加密? MD5英文全称“Message-Digest Algorithm 5 ...

  2. Android DES AES MD5加密

    AES加密: <span style="font-size:18px;">package com.example.encrypdate.util; import jav ...

  3. Android String操作

    android String.valueOf(ch).getBytes("GBK") --------------------------------------------- S ...

  4. Android string.xml error: Apostrophe not preceded by \

    Android string.xml error: Apostrophe not preceded by \ 遇到了这个错误,编译无法通过 error: Apostrophe not preceded ...

  5. 【Android】android string.xml前后加空格的技巧

    android string.xml 文字中间加入空格 <string name="password">密    码</string> &#160 ...

  6. Android 手机卫士--md5加密过程

    在之前的文章中,我们将用户的密码使用SharedPreferences存储,我们打开/data/data/com.wuyudong.mobilesafe/shared_prefs文件夹下的 confi ...

  7. android string.xml %问题

    反复检查后发现是string.xml中的 % 导致编译失败, 这是由于新的SDK采用了新版本的aapt(Android项目编译器),这个版本的aapt编译起来会比老版本更加的严格,然后在Android ...

  8. Android开发之MD5加密

    将字符串进行MD5加密,返回加密后的字符串 public static String encode(String password) { try { StringBuffer sb = new Str ...

  9. android中的MD5、Base64、DES/3DES/ADES加解密

    MD5摘要算法: <span style="font-size:18px;">主要代码: String s = edit.getText().toString(); i ...

随机推荐

  1. hdu3534,个人认为很经典的树形dp

    题目大意为,求一个树的直径(最长路),以及直径的数量 朴素的dp只能找出某点开始的最长路径,但这个最长路径却不一定是树的直径,本弱先开始就想简单了,一直wa 直到我看了某位大牛的题解... 按照那位大 ...

  2. [LeetCode] 35. Search Insert Position 解决思路

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  3. RSA算法python实现

    RSA算法是一种非对称加密算法,是现在广泛使用的公钥加密算法,主要应用是加密信息和数字签名.详情请看维基:http://zh.wikipedia.org/wiki/RSA%E5%8A%A0%E5%AF ...

  4. RSA实例破解

    Description: Decode the message. You intercept the following message, which you know has been encode ...

  5. python unicodeDecode error

    混淆了 python2 里边的 str 和 unicode 数据类型. 0. 你需要的是让编码用实际编码而不是 ascii 1. 对需要 str->unicode 的代码,可以在前边写上 imp ...

  6. Java毫秒转换成日期格式

    import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.uti ...

  7. HDOJ 3622 - Bomb Game 2-sat+二分....细心...

    题意: 有N个炸弹..每个炸弹有两个位置可以选择..把炸弹放到其中一个地方去...炸弹的爆炸范围是其为圆心的圆...两个炸弹不能有攻击范围上的重合..问要满足条件..炸弹爆炸范围的半径最长能是多少.. ...

  8. 性能优化之NSDateFormatter

    为什么要优化NSDateFormatter? 优化方式有哪些? 为什么要优化NSDateFormatter? 首先,过度的创建NSDateFormatter用于NSDate与NSString之间转换, ...

  9. Swift补基础之Selector、条件编译、编译标记、NSObject

    在swift中使用条件编译比较直接 #if <condition> #elseif <condition> #else #endif 例如 :在debug模式和release模 ...

  10. java 不同意同一账户不同IP 同一时候登录系统解决的方法 兼容IE Firefox

    需求就是 不同意同一个账户同一时间登录系统.仅仅要有一个账户在线其它人就是不能用这个账户. 功能非常easy,过程非常纠结 . 这篇文章攻克了兼容IE.Firefox 浏览器下,不同IP 地址 同一用 ...