Android development often requires a certain number of demos
From now on MD5 some cryptographic algorithm extracts to see how it is implemented
First, we have to be clear about why encryption?
1 Data security Processing
2 Preventing data theft
3 effective to avoid malicious attacks
4 Guaranteed File Integrity
5 optimized search as file (data) index exists etc.
The above is the purpose of basic encryption technology
2 What are the encryption technologies that are currently being used in Android?
This is the site found some of the data is mainly 2 algorithm one is SHA1 algorithm one is MD5 encryption
Other teas. Symmetric encryption algorithms are more efficient
Tea (Tiny encryption algorithm) is a small symmetric encryption and decryption algorithm that supports 128-bit password, which can only encrypt/decrypt 8 bytes of data at a time like Blowfish. Tea is characterized by fast speed, high efficiency and easy implementation. Tea has also developed several version numbers, each of which is Xtea, Block tea and Xxtea, as attacks on tea continue to occur.
The default encryption algorithm used by Android 2.2.1 is AES 256-sha1, but starting with Android 2.3 released in 2010, it defaults to a weaker cryptographic algorithm rc4-md5.
When an Android app establishes an SSL encrypted connection, it will be encrypted by default using RC4-MD5 if not specified.
One might suspect that the U.S. National Security Agency (NSA) has bought Android developers to reduce the difficulty of hacking encrypted connections to monitor Android users.
But Georg Lukas after analyzing the Android source code found. The order of the default cryptographic algorithms is sun/Oracle's Java definition. The Java specification defines the TLS secure transport Protocol encryption algorithm list for the first two types of RC4 and MD5. The 2011 release of the Java 7 added Elliptic curve encryption algorithm improved the encryption list. But Android is based on JDK 6 and still follows a list of default cryptographic algorithms defined ten years ago.
Next we mostly use SHA1 and MD5 so how do we implement a MD5 encryption?
Generally we have the following steps in implementing MD5 encryption
1 First get an information digest messagedigest then set MD5
2 we get the data to encrypt such as password= "123456"
3 Convert this data to byte data password.getbytes ()
4 loops to process every number of bytes
The main thing here is to do 2 processing one is to do with each byte data and the operation is usually the number with the previous 16 binary
such as int number = P $0xff;
The resulting number ' is then converted to 16 binary
integer.tohexstring (number);
Assuming this number is converted to a length of 1 then we'll make 0.
Less than eight binary then we'll fill it up.
Algorithm idea:
1 with each byte go and 11111111 do with the operation and get the value of an int type byte&11111111
2 convert int to 16 binary and return string type
3 Less than 8 2 binary bits on completion
5 detailed implementation algorithms such as the following
public class Demo {public static void main (string[] args) throws NoSuchAlgorithmException {//Information digest messagedigest Digest = M Essagedigest.getinstance ("MD5"); String password = "123456";//cryptographic character StringBuffer buffer = new StringBuffer (); byte [] result = Digest.digest (password.getbyte s ()); for (byte b:result) {int number = B & 0xff;//not in standard encryption//conversion to 16 binary string numberstr = integer.tohexstring (number); if (Numberstr.length () ==1) {Buffer.append ("0");} Buffer.append (NUMBERSTR);} MD5 encryption Result System.out.println (buffer.tostring ());}}
General large-scale site or bank is the data for multiple MD5 encryption generally at more than 5 times the bank generally in 20 times so very difficult to be cracked also is that every byte operation is not necessarily in accordance with the standard and 16-bit encryption can be used in a random way for example and the previous 32-bit data Or even with other characters that can be encrypted in an inverse way, these are called salt-adding.
In Andorid we mainly use the Md5utils tool to encrypt by default using the standard encryption method
Like we can do it where we want to encrypt it.
String password = "123456";
Md5utils.encode (password);
Here's a md5utils little encryption tool that you can look at.
Md5utils Download
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Shian Andorid below MD5 concrete Realization Idea Summary