A brief summary of several common information encryption methods in iOS

Source: Internet
Author: User
Tags hmac md5 encryption openssl enc openssl md5 rfc asymmetric encryption

I. MD5 encryption

MD5 encryption is one of the most commonly used encryption methods, which is to generate a 32-bit alphanumeric mixed code from a string with corresponding characteristics.

MD5 main features are irreversible, the same data MD5 value is certainly the same, different data MD5 value is not the same (nor absolute, but the basic can not be the same). The MD5 algorithm also has the following properties: 1, compressibility: Any length of data, the calculated length of the MD5 value is fixed. 2, easy to calculate: It is easy to calculate the MD5 value from the original data. 3, anti-modification: Any changes to the original data, even if only 1 bytes modified, the resulting MD5 value is very different. 4, weak anti-collision: known raw data and its MD5 value, it is very difficult to find a data with the same MD5 value (that is, falsification of data). 5, strong anti-collision: To find two different data, so that they have the same MD5 value, is very difficult. MD5 Although said to be irreversible but because of the existence of the site http://www.cmd5.com, specifically used to query MD5 code, so some simple MD5 code can be found here source code. In order to make MD5 code more secure emerges a lot of other methods such as adding salt. It is hard to find the MD5 code that is long enough to get the salt. Terminal code: $ echo-n ABC|OPENSSL MD5 to string ABC encryption two. HMAC EncryptionThis encryption method needs to be a key, and then the password to MD5 and HMAC encryption, the database needs to store the key used at that time and password encrypted ciphertext when the user log in again to fill in the password with the key encryption and also add the current time (accurate to minutes) again HMAC encryption, The server will also take out the previously stored ciphertext plus time to encrypt again. So even if the hacker intercepted the password in the middle of the cipher can only be decoded in 1 minutes can be effective, greatly enhanced security. Server in order to take into account the delay of the network generally will be more than an answer, such as 23 points over the password he will be 23 points and 22 points of the calculation and user matching as long as the previous allowed to login. User registration and User login--------------------------------------------------------------------------------- three. Base64 Encryption

In MIME-formatted e-mail messages, base64 can be used to encode binary byte sequence data into text that consists of sequences of ASCII characters. When used, specify Base64 in the transfer encoding mode. The characters used include 26 uppercase and lowercase letters, plus 10 digits, and a plus sign "+", a slash "/", a total of 64 characters, and an equal sign "=" to use as a suffix.

The full base64 definition is visible in RFC 1421 and RFC 2045. The encoded data is slightly longer than the original data for the original 4/3.

Schematic diagram

Terminal Instructions CD to find the current directory encryption: $ base64 Abc.png-o abc.txt decryption: $ base64 Abc.txt-o 123.png-d four. Symmetric encryption AlgorithmAdvantages: The algorithm exposes, the computation is small, the encryption speed is fast, the encryption efficiency is high, the reversible disadvantage:the two sides use the same key, the security is not guaranteedPresent situation:symmetric encryption is much faster than public key encryption, and in many cases symmetric encryption is required .Compared to Des and 3DES algorithms, the AES algorithm has higher speed and resource use efficiency, the security level is also higher than the next generation of Encryption Standard NECB: Electronic code, that is, each block is an independent encryption NCBC: Cipher block chain, using a key and an initialization vector (IV) Performing a cryptographic conversion to data ECB and CBC differences: CBC is more complex and more secure, with 8-bit vectors (8 0 words equal to the ECB). A letter is changed in the clear text, the corresponding line of the ECB cipher will change, and CBC ciphertext will change from that line. ECB terminal command: $ openssl enc-des-ecb-k 616263-nosalt-in msg1.txt-out MSG1.BINCBC terminal command: $ openssl enc-des-cbc-k 616263-iv 00 00000000000000-nosalt-in Msg1.txt-out Msg2.bin Five. RSA EncryptionRSA Asymmetric encryption algorithm requires two keys: Public key (PublicKey) and private key (Privatekey) public key is a pair with private key, if data is encrypted with public key, only the corresponding private key can be decrypted If the data is encrypted with a private key, then only the corresponding public key can decrypt the characteristics: the characteristics of asymmetric cryptography: The complexity of the algorithm, the security depends on the algorithm and the key but because of its complex algorithm, which makes the encryption and decryption speed is not symmetric encryption decryption speed symmetric cipher system has only one key, and is private, if you want to decrypt it, you have to let the other person know the key. So the security is to ensure the security of the key, the asymmetric key system has two keys, one of which is public, so that you do not need to transfer the other person's key like a symmetric password basic encryption principle: (1) Find two "very large" prime numbers: P & Q (2) N = p * Q (3) M = (p–1 ) * (q–1) (4) Find out the integer e,e and M coprime, that is, except 1, no other Convention number (5) to find the integer D, so that the E*d divided by M 1, ie (e * D)% m = 1 after the above preparations, you can get: E is the public key, responsible for encrypting D is the private key The contact encryption algorithm, assuming that x is encrypted (x ^ E)% n = yn according to the Fermat small definition, the decryption operation can be done according to the following formula (Y ^ D)% n = X But the RSA encryption algorithm is inefficient, the encryption time for large data is very long, generally used for small data. Common scenario: Division to send a message to Headquarters, the entire message is MD5 to get a message digest, and then the paper digest to be encrypted with the public key. Then send the message along with this RSA cipher. Headquarters after receiving the message to determine whether the message was tampered with in the middle, the ciphertext is decrypted with the private key to get the message digest, and then the whole message MD5 to be compared if the same is not changed.

A brief summary of several common information encryption methods in iOS

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.