Android Security Encryption: Message Digest Digest detailed _android

Source: Internet
Author: User
Tags md5 md5 encryption sha1 asymmetric encryption

Android security encryption feature article index

  1. Android Secure encryption: Symmetric encryption
  2. Android Secure encryption: Asymmetric encryption
  3. Android Secure encryption: Message digest Digest
  4. Android Security Encryption: Digital signatures and digital certificates
  5. Android Secure encryption: HTTPS programming

The above learning all content, symmetric encryption, asymmetric encryption, message digest, digital signature and other knowledge is to understand the work of digital certificates as a preliminary knowledge. Digital certificate is the ultimate weapon in cryptography, is the crystallization of the wisdom of human thousands of years history, only after understanding the working principle of digital certificate, can we understand the secure communication mechanism of HTTPS protocol. It will eventually be handy in the SSL development process.

In addition, the two knowledge points of symmetric encryption and message digest can be used separately.

Knowledge Point Series:

Digital certificates use all the knowledge you have learned

    1. Symmetric encryption and asymmetric encryption are used to achieve the secret key exchange, after which the two parties use the secret key for symmetric encrypted communication.
    2. Message digest and asymmetric encryption to achieve digital signature, the root certificate authority to sign the target certificate, at the time of verification, the root certificate with the public key to verify it. If the checksum succeeds, the certificate is trusted.
    3. The Keytool tool can create certificates, then submit them to the root certification authority for direct use of self-signed certificates, as well as output the RFC format information for certificates.
    4. Digital signature technology realizes the guarantee of identity authentication and data integrity.
    5. The encryption technology guarantees the confidentiality of the data, the message digest algorithm guarantees the integrity of the data, the high efficiency of symmetric encryption guarantees the reliability of the processing, and the digital signature technology guarantees the non-repudiation of the operation.

Through the above content of learning, we should be able to grasp the following knowledge points:

    1. Basics: Bit bits, bytes, characters, character encodings, incoming transformations, IO
    2. Know how to use symmetric encryption to solve problems in actual development
    3. Know symmetric encryption, asymmetric encryption, message digest, digital signature, digital certificate is to solve the problem of what happened
    4. Understanding the SSL communication process
    5. How to request HTTPS interface in actual development

1. Common algorithms

MD5, SHA, CRC, etc.

2. Use the scene

    1. MD5 encryption of user passwords to the database
    2. Software download station uses message digest to calculate file fingerprints to prevent tampering
    3. Digital signatures (back knowledge points)
    4. Baidu Cloud, 360 network disk and other cloud disk pass function is SHA1 value
    5. Eclipse and the Android Studio development tool determine if the V4,V7 package is conflicting based on the SHA1 value
    6. It is said that the bank's password uses MD5 encryption (because MD5 is irreversible)

For example software download station data fingerprint: http://dev.mysql.com/downloads/installer/

3. Use steps

Commonly used algorithms: MD5, SHA, CRC
messagedigest digest = messagedigest.getinstance ("MD5");
Byte[] result = Digest.digest (Content.getbytes ());
The results of the message digest are generally converted to a 16-string representation of
string hex = Hex.encode (result);
The MD5 result is 16 bytes (128 bits), converted to 16, and the length is 32 characters
//sha The result is 20 bytes (160 bits), and the conversion to 16 is the 40-character
System.out.println ( HEX);

The result of the message digest is fixed length, no matter how large your data is, even if it is only one byte or a G file, the result of the summary is fixed length.

Often hear people ask such a question, MD5 summary after the end of the number of digits? Some people say it is 16, some say 128, and some say it's 32-bit. How long it is, this time we have to understand that 16 digits refers to the number of bytes, 128 bits refers to the bit, 32 digits to the result of the conversion to the 16-digit display of the number of characters.

4. Principle of Digital Digest

/Get instance MessageDigest Digest = messagedigest.getinstance ("MD5"); Digest.update (
Key.getbytes ());
byte[] bytes = Digest.digest (Key.getbytes ());
StringBuilder sb = new StringBuilder ();
 for (int i = 0; i < bytes.length i++) {String hex = integer.tohexstring (BYTES[I]&0XFF);
 if (hex.length () = = 1) {sb.append ("0");
} sb.append (hex);

 

String hexstring = sb.tostring (); 

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.