Password Encryption MD5

Source: Internet
Author: User
Tags sha1 sha1 encryption

Password Encryption MD5
    • Create a NSString class
  1. Nsstring+password.h

    1 //2 //nsstring+password.h3 //03. Data Encryption4 //5 //Created by Wyh on 15-1-10.6 //Copyright (c) 2015 Itcast. All rights reserved.7 //8 9 Ten #import<Foundation/Foundation.h> One  A @interfacensstring (Password) -  - /** the * 32-bit MD5 encryption -  * - * @return 32-bit MD5 encryption results -  */ +-(NSString *) MD5; -  + /** A * SHA1 Encryption at  * - * @return SHA1 Encryption Results -  */ --(NSString *) SHA1; -  - @end

  2. Nsstring+password.m
    1 //2 //NSSTRING+PASSWORD.M3 //Data Encryption4 //5 //Created by Wyh on 15-1-10.6 //Copyright (c) 2015 Itcast. All rights reserved.7 //8 9 #import "nsstring+password.h"Ten #import<CommonCrypto/CommonDigest.h> One  A @implementationnsstring (Password) -  - #pragmaMark uses MD5 to encrypt strings the-(NSString *) MD5 - { -     Const Char*cstr =[self utf8string]; -UnsignedCharDigest[cc_md5_digest_length]; +  - cc_md5 (CStr, strlen (CSTR), digest); +  Ansmutablestring *result = [nsmutablestring stringwithcapacity:cc_md5_digest_length *2]; at  -      for(inti =0; i < cc_md5_digest_length; i++) { -[Result AppendFormat:@"%02x", Digest[i]]; -     } -  -     returnresult; in } -  to #pragmaMark uses SHA1 to encrypt strings +-(NSString *) SHA1 - { the     Const Char*cstr =[self utf8string]; *NSData *data =[NSData datawithbytes:cstr length:self.length]; $ uint8_t Digest[cc_sha1_digest_length];Panax Notoginseng  - cc_sha1 (Data.bytes, Data.length, Digest); the  +nsmutablestring *result = [nsmutablestring stringwithcapacity:cc_sha1_digest_length *2]; A  the      for(inti =0; i < cc_sha1_digest_length; i++) { +[Result AppendFormat:@"%02x", Digest[i]]; -     } $      $     returnresult; - } -  the @end

    • Steps to use:

    1. Add class to the class used: #import "Nsstring+password.h"

    2. Returns the encrypted string with the string tone method to be encrypted MD5 or SHA1: encrypted result =[self.userpwd.text MD5];

    3. End

    • Brief introduction
    1. Message Digest algorithm MD5 (Chinese named message Digest Algorithm version fifth) is a hash function widely used in the field of computer security to provide integrity protection for messages. The file number of the algorithm is RFC 1321
    2. MD5 is used to ensure complete consistency of information transmission. is one of the most widely used hashing algorithms (also translation digest algorithm, hashing algorithm), mainstream programming language has generally MD5 implementation of MD5 is a typical application of a byte string to produce fingerprints to prevent being "tampered with". For example, you can generate a MD5 value for a Readme.txt and record that if someone modifies anything in the file, the MD5 value that is recalculated for that file will change MD5 also widely used in the operating system login authentication, such as UNIX, all kinds of BSD system login password, Digital signature and many other aspects
    3. MD5 is irreversible
    4. MD5 the same data encryption result is the same? A taboo on the password
    5. MD5 in the use of the time to add a "salt" and the private key, or it will be cracked, it is better to define a macro, to save the part of the string
    6. Hack website: http://www.cmd5.com

Password Encryption MD5

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.