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