MD5 encryption, BASE64 encryption/decryption, AES encryption/decryption

Source: Internet
Author: User

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

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.