Reprinted from ...
①, string encryption md5,32 bit 16 binary string
②, encrypting a string with ASCII characters
③, programming the ASCII string 16 binary string
Importjava.security.MessageDigest; Public classStringUtils { Public Staticstring replaceurlwithplus (string url) {if(URL! =NULL) { returnUrl.replaceall ("http://(.) *?/"," "). ReplaceAll (" [.:/,%?&=] "," + "). ReplaceAll (" [+]+ "," + "); } return NULL; } Public StaticString EncodeMD5 (String text)throwsException {messagedigest MD= Messagedigest.getinstance ("MD5"); Md.update (Text.getbytes ("Us-ascii")); byte[] Digest =md.digest (); StringBuffer MD5=NewStringBuffer (); for(inti = 0; i < digest.length; i++) {md5.append (Character.fordigit (digest[i)& 0xF0) >> 4, 16)); Md5.append (Character.fordigit (digest[i)& 0xF), 16)); } returnmd5.tostring (); } Public StaticString Encodemd5ascii (String text)throwsException {messagedigest MD= Messagedigest.getinstance ("MD5"); Md.update (Text.getbytes ("Us-ascii")); byte[] Digest =md.digest (); return NewString (Digest, "Us-ascii"); } Public StaticString Decodemd5hex (String text)throwsException {byte[] Digest =text.getbytes (); StringBuffer MD5=NewStringBuffer (); for(inti = 0; i < digest.length; i++) {md5.append (Character.fordigit (digest[i)& 0xF0) >> 4, 16)); Md5.append (Character.fordigit (digest[i)& 0xF), 16)); } returnmd5.tostring (); }}
Some transcoding of Android strings