Some transcoding of Android strings

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.