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