ios--commonly used encryption methods

Source: Internet
Author: User
Tags md5 encryption

iOS code encryption commonly used encryption methods, common iOS code encryption algorithms include MD5 encryption, AES encryption, BASE64 encryption.

Three great algorithms for how iOS code encryption is encrypted:

///////////////////////////////////////////////////////////////////

MD5 How to use iOS code encryption

///////////////////////////////////////////////////////////////////

Create the MD5 class with the following code

#import <Foundation/Foundation.h>

@interface Cjmd5:nsobject

+ (NSString *) Md5hexdigest: (NSString *) input;

@end

#import "CJMD5.h"

#import <CommonCrypto/CommonDigest.h>

@implementation CJMD5

+ (NSString *) Md5hexdigest: (NSString *) input {

const char * str = [input utf8string];

unsigned char result[cc_md5_digest_length];

CC_MD5 (Str,strlen (str), result);

nsmutablestring *ret = [nsmutablestring stringwithcapacity:cc_md5_digest_length];

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

[ret appendformat:@ "%02x", result];

}

return ret;

}

@end

MD5 is irreversible only if encryption is not decrypted, iOS code is encrypted using the following methods

NSString *username = @ "Woshinidaye";

NSString *password = @ "Daohaosiquanjia";

MD5 encryption

NSString *MD5 = [CJMD5 Md5hexdigest:password];

NSLog (@ "%@", MD5);

///////////////////////////////////////////////////////////////////

How to encrypt iOS code using AES encryption

///////////////////////////////////////////////////////////////////

AES Encryption

NSString *encrypteddata = [Aescrypt encrypt:username password:password];//Encryption

NSString *message = [Aescrypt decrypt:encrypteddata Password:password];

NSLog (@ "Encrypted result:%@", EncryptedData);

NSLog (@ "decryption result:%@", message);

///////////////////////////////////////////////////////////////////

BASE64 How to encrypt iOS code using encryption

///////////////////////////////////////////////////////////////////

. h

+ (NSSTIRNG *) encodebase64string: (NSString *) input;

+ (NSSTIRNG *) decodebase64string: (NSString *) input;

+ (NSString *) Encodebase64data: (NSData *) data;

+ (NSString *) Decodebase64data: (NSData *) data;

. m

+ (NSString *) encodebase64string: (NSString *) input {

NSData *data = [input datausingencoding:nsutf8stringencoding allowlossyconversion:yes];

data = [GTMBase64 encodedata:data];

NSString *base64string =[[NSString alloc] Initwithdata:data encoding:nsutf8stringencoding];

return base64string;

}

+ (NSString *) decodebase64string: (NSString *) input {

NSData *data = [input datausingencoding:nsutf8string allowlossyconversion:yes];

data = [GTMBase64 decodedata:data];

NSString *base64string = [[NSString alloc] Initwithdata:data encoding:nsutf8stringencoding];

return base64string;

}

+ (NSString *) Encodebase64data: (NSData *) Data {

data = [GTMBase64 encodedata:data];

NSString *base64string = [[NSString alloc] Initwithdata:data encoding:nsutf8stringencoding];

return base64string;

}

+ (NSString *) Decodebase64data: (NSData *) Data {

data = [GTMBase64 encodedata:data];

NSString *base64string = [[NSString alloc] Initwithdata:data encoding:nsutf8stringencoding];

return base64string;

}

BASE64 How to encrypt iOS code using encryption

BASE64 encryption

NSString *baseencodestring = [GTMBase64 Encodebase64string:password];

NSString *basedecodestring = [GTMBase64 decodebase64string:baseencodestring];

NSLog (@ "baseencodestring:%@", baseencodestring);

NSLog (@ "basedecodestring:%@", basedecodestring);

///////////////////////////////////////////////////////////////////

iOS App code encryption

///////////////////////////////////////////////////////////////////

In addition to iOS code encryption for the three algorithms above, iOS app code encryption is also important.

The main iOS code encryption is as follows, iOS app code encryption is the iOS encryption service provided by the Love encryption platform.

1. Before using encryption

2. After compiling, before encryption

3. After compiling, after encryption

(1) Local Data encryption

Encrypt nsuserdefault,sqlite storage file data, protect account and key information.

(2) URL encoding encryption

Encrypt URLs that appear in the program to prevent URLs from being statically parsed

(3) Network transmission data encryption

Provides encryption scheme for transmitting data to the client, which effectively prevents interception through the network interface.

(4) Method body, method name high-level confusion

Confuse the application's method name and method body encryption to ensure that the code cannot be parsed after the password is reversed

(5) Program Structure mix-and-discharge encryption

The application logical structure is scrambled and mixed to ensure that the source readability is minimized.

ios--commonly used encryption methods

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.