六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 32|回复: 0

MD5加密及随机数生成

[复制链接]

升级  98.8%

328

主题

328

主题

328

主题

进士

Rank: 4

积分
994
 楼主| 发表于 2013-2-3 10:09:21 | 显示全部楼层 |阅读模式
今天贴两个简单的方法,需要的时候不用自己再写,
 

public static string md5(string plaintext){messagedigest m;try {m = messagedigest.getinstance("md5");m.reset(); m.update(plaintext.getbytes()); byte[] digest = m.digest(); biginteger bigint = new biginteger(1,digest); string hashtext = bigint.tostring(16); // now we need to zero pad it if you actually want the full 32 chars. while(hashtext.length() < 32 ){   hashtext = "0"+hashtext; } return hashtext;} catch (nosuchalgorithmexception e) {e.printstacktrace();return system.currenttimemillis() + "";} }public static string randomcreator(int num){random random = new random();int i=random.nextint();i=math.abs(i);string tem=string.valueof(i);while(tem.length()<num){tem+="0";}return tem.substring(0,num);}  
 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表