1. Download the Gtmbase64-master and Aescrypt-objc-master from GitHub and import the project as shown in.
2. Pre-use configuration and precautions:
(1) gtmbase64.m in build phases need to be set-fno-objc-arc
(2) Import #import in #import "nsstring+base64.m" File <Foundation/Foundation.h>
(3) Add #import in the #import "gtmbase64.m" File <CommonCrypto/CommonCrypto.h>
3. CusMD5.h and cusmd5.m files
#import <Foundation/Foundation.h> @interface cusmd5:nsobject+ (NSString *) md5string: (NSString *) str; @end # Import "CusMD5.h" #import <CommonCrypto/CommonDigest.h> @implementation cusmd5+ (NSString *) md5string: (nsstring *) str { const char *original_str = [str utf8string]; unsigned char result[cc_md5_digest_length]; CC_MD5 (Original_str, strlen (ORIGINAL_STR), result); nsmutablestring *hash = [nsmutablestring string]; for (int i = 0; i < cc_md5_digest_length; i++) [hash appendformat:@ "%02x", Result[i]]; return [hash lowercasestring]; } @end
---> MD5 can only be called an irreversible encryption algorithm, can only be used as a test process, can not restore its original text.
4. Basic use
#import "ViewController.h" #import "CusMD5.h" #import "GTMBase64.h" #import "AESCrypt.h" @interface Viewcontroller () @ End@implementation viewcontroller-(void) viewdidload {[Super viewdidload]; The string to encrypt nsstring *strforen = @ "requires an encrypted string"; MD5 encryption NSString *strenres = [CusMD5 Md5string:strforen]; NSLog (@ "MD5 encryption:%@", strenres); Base64 encryption NSData *dataen = [Strforen datausingencoding:nsutf8stringencoding]; NSData *dataenres = [GTMBase64 Encodedata:dataen]; Turn the encryption result into a string nsstring *base64enres = [[NSString alloc] Initwithdata:dataenres encoding:nsutf8stringencoding]; NSLog (@ "base64 encryption:%@", base64enres); Base64 decryption NSData *resdebase64 = [GTMBase64 decodedata:dataenres]; NSString *strdebase64 = [[NSString alloc] initwithdata:resdebase64 encoding:nsutf8stringencoding]; NSLog (@ "Base64 decryption:%@", strDeBase64); AES encryption NSString *straesenres = [Aescrypt encrypt:strforen password:@ "secret"]; NSLog (@ "AES encryption:%@", straesenres); AesDecrypt NSString *straesderes = [Aescrypt decrypt:straesenres password:@ "secret"]; NSLog (@ "AES decryption:%@", straesderes);} -(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end
MD5 encryption, BASE64 encryption/decryption, AES encryption/decryption