Android String 转 MD5
/**
* 将字符串转成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的更多相关文章
- Android数据加密之MD5加密
前言: 项目中无论是密码的存储或者说判断文件是否是同一文件,都会用到MD5算法,今天来总结一下MD5加密算法. 什么是MD5加密? MD5英文全称“Message-Digest Algorithm 5 ...
- Android DES AES MD5加密
AES加密: <span style="font-size:18px;">package com.example.encrypdate.util; import jav ...
- Android String操作
android String.valueOf(ch).getBytes("GBK") --------------------------------------------- S ...
- Android string.xml error: Apostrophe not preceded by \
Android string.xml error: Apostrophe not preceded by \ 遇到了这个错误,编译无法通过 error: Apostrophe not preceded ...
- 【Android】android string.xml前后加空格的技巧
android string.xml 文字中间加入空格 <string name="password">密 码</string>   ...
- Android 手机卫士--md5加密过程
在之前的文章中,我们将用户的密码使用SharedPreferences存储,我们打开/data/data/com.wuyudong.mobilesafe/shared_prefs文件夹下的 confi ...
- android string.xml %问题
反复检查后发现是string.xml中的 % 导致编译失败, 这是由于新的SDK采用了新版本的aapt(Android项目编译器),这个版本的aapt编译起来会比老版本更加的严格,然后在Android ...
- Android开发之MD5加密
将字符串进行MD5加密,返回加密后的字符串 public static String encode(String password) { try { StringBuffer sb = new Str ...
- android中的MD5、Base64、DES/3DES/ADES加解密
MD5摘要算法: <span style="font-size:18px;">主要代码: String s = edit.getText().toString(); i ...
随机推荐
- android 复杂的json数据解析
1.通过谷歌的Gson来进行解析: json数据:sTotalString = {"message":"success","result": ...
- SQL-Customers Who Never Order
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL qu ...
- SRM 600 DIV1
A 按位讨论,取最小值; B 数据范围不大,首先要确定枚举角度; 状压枚举palindromes的列比较科学; 列确定后,目标就是求获得rcnt行的最小代价: dp[i][cnt]表示扫描到第i行,已 ...
- cocos 的CCScheduler模块
scheduleSelector函数->查找m_pHashForTimers是否有存储回调的Obj类实例,否,创建新条目tHashTimerEntry,指向回调类实例,tHashTimerEnt ...
- JSP入门:介绍什么是JSP和Servlet(转)
转自:http://developer.51cto.com/art/200907/134506.htm JSP入门:什么是jsp? JSP(Java Server Pages)是由Sun Micros ...
- PHP中字符串类型与数值类型混合计算
字符串转数值的规则 当一个字符串被当作一个数值来取值,其结果和类型如下: 如果该字符串没有包含 '.','e' 或 'E' 并且其数字值在整型的范围之内(由 PHP_INT_MAX 所定义),该字符串 ...
- Mongodb 条件查询
1.1 查询出所有数据的指定键(name ,age ,country) db.persons.find({},{name:1,age:1,country:1,_id:0}) 2.查询条件 2.查询条件 ...
- 【实验 1-1】编写一个简单的 TCP 服务器和 TCP 客户端程序。程序均为控制台程序窗口。
在新建的 C++源文件中编写如下代码. 1.TCP 服务器端#include<winsock2.h> //包含头文件#include<stdio.h>#include<w ...
- Swift2.0下UICollectionViews拖拽效果的实现
文/过客又见过客(简书作者)原文链接:http://www.jianshu.com/p/569c65b12c8b著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 原文UICollecti ...
- ViewController详解
一.生命周期 当一个视图控制器被创建,并在屏幕上显示的时候. 代码的执行顺序1. alloc 创建对象,分配空间2.init (initWit ...