Android Phone defender--MD5 Encryption process

Source: Internet
Author: User
Tags md5 encryption

In the previous article, we stored the user's password using sharedpreferences, and we opened the CONFIG./data/data/com.wuyudong.mobilesafe/shared_prefs file under the folder Import to local, view content:

<?XML version= ' 1.0 ' encoding= ' utf-8 ' standalone= ' yes '?><Map>    <stringname= "MOBILE_SAFE_PSD">123</string>    <Booleanname= "Open_update"value= "false" /></Map>

Passwords are actually used in plaintext, which is very insecure. MD5 encryption is used here

This article address: http://www.cnblogs.com/wuyudong/p/5941131.html, reprint please indicate the source.

Write the Md5util tool class with the following code:

 Packagecom.wuyudong.mobilesafe.Utils;/*** Created by Wuyudong on 2016/10/9.*/Importjava.security.MessageDigest;Importjava.security.NoSuchAlgorithmException; Public classMd5util {/*** To encrypt the specified string according to the MD5 algorithm * *@paramPSD requires encrypted password plus salt processing *@returnthe string after MD5*/     Public StaticString Encoder (string psd) {Try {            //Add salt treatmentPSD = PSD + "Mobilesafe"; //1, specifying the encryption algorithm typeMessageDigest digest = messagedigest.getinstance ("MD5"); //2, convert the string that needs to be encrypted into an array of type Byte, and then perform a random hash process            byte[] bs =digest.digest (Psd.getbytes ()); //3, Loop through BS, and let it generate 32-bit strings, fixed notation//4, stitching the string processStringBuffer StringBuffer =NewStringBuffer ();  for(byteb:bs) {                inti = B & 0xFF; //I of type int needs to be converted to 16 mechanism charactersString hexstring =integer.tohexstring (i);                if(Hexstring.length () < 2) {hexstring= "0" +hexstring;            } stringbuffer.append (hexstring); }            //5, Print testSystem.out.println (stringbuffer.tostring ()); returnstringbuffer.tostring (); } Catch(nosuchalgorithmexception e) {e.printstacktrace (); }        return""; }}

MD5 encryption: Converting a string to a 32-bit string (16 characters (0~F)) is irreversible

Example: 123 after encryption: 202cb962ac59075b964b07152d234b70

Android Phone defender--MD5 Encryption process

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.