How to encrypt strings in iOS/ios implementation of NSString classification in MD5 encryption/ios

Source: Internet
Author: User
Tags md5 encryption

After reading, you will learn:

1 learning about classification implementations in iOS development,

2 and the writing of the class method,

3 and MD5 encryption/decryption of the string.

---------------------------wolfhous------------------

[1] New project, new classification

[2] nomenclature of classification and selection of classes

[3] class methods for writing NSString classifications, as well as implementing class methods, and how MD5 is encrypted

[4] Test encryption results

[5] Decryption: Direct Baidu MD5 decryption, random song website in, input decryption key, in my demo,

Wolfhous Normal encryption 44bf025d27eea66336e5c1133c3827f7

Wolfhous Encryption 44fb461963aae22772a18557787c63b3

-------------------------wolfhous-----------------------

It can be seen that the secret of the normal website cannot be decrypted, it is suggested that the user will use the encryption when they enter the password at registration. Of course, a lot of encryption method n Many, I this only lists a simple way, below the source code

#import "Nsstring+md5string.h"

introduction of necessary header files

#import <CommonCrypto/CommonDigest.h>

@implementation nsstring (md5string)

/** MD5 General Encryption * /

+ (nsstring *) md5string: (nsstring *) str

{

Const char *mypasswd = [str utf8string];

unsigned char mdc[];

cc_md5(mypasswd, (cc_long)strlen(MYPASSWD), MDC);

nsmutablestring *md5string = [nsmutablestring string];

for (int i = 0; i< ; i++) {

[Md5string AppendFormat:@ "%02x", Mdc[i]];

}

return md5string;

}

/** MD5 NB ( mean ) encryption * /

+ (nsstring *) MD5STRINGNB: (nsstring *) str

{

Const char *mypasswd = [str utf8string];

unsigned char mdc[];

cc_md5(mypasswd, (cc_long)strlen(MYPASSWD), MDC);

nsmutablestring *md5string = [nsmutablestring string];

[Md5string AppendFormat:@ "%02x", mdc[0]];

for (int i = 1; i< ; i++) {

[Md5string AppendFormat:@ "%02x", mdc[i]^mdc[0]];

}

return md5string;

}

@end

How to encrypt strings in iOS/ios implementation of NSString classification in MD5 encryption/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.