[Android]MD5加密字符串
墨初 知识笔记 34阅读
用消息摘要5加密字符串,返回加密后的字符串(实际上是字符串的消息摘要)。publicstaticStringmd5(string string){ byte[]hash;请尝试{hash=消息摘要。Getinstance(' MD5 ')。摘要(字符串。getbytes(' UTF-8 ');} catch(没有这样的算法异常){thrownewruntimeexception('哎,MD5应该支持吗?e);} catch(不支持的编码异常){thrownewruntimeexception('嗯,应该支持UTF-8吧?e);} StringBuilderhex=新的字符串生成器(哈希。长度* 2);for(byteb : hash){ if((B0 xff)0x 10)hex .append(" 0 ");十六进制系统追加(整数。tohexstring(b0xFF));}返回十六进制。tostring();}参考:在线测试MD5:作者:博客:日期:2012年3月26日
![[Android]MD5加密字符串](https://www.feiniaomy.com/xzm_artimg/2309161325yw1s84897122_0.png)
标签: