Encryption and decryption are no longer your nightmare

Source: Internet
Author: User

Encryption and decryption are no longer your nightmare

You may have used encryption and decryption algorithms in your project, such as AES and DES. You have downloaded a source code from GitHub, imported it to your project, imported the header file, and used it.

In fact, things are far less simple than you think. You need to encrypt the string, right? You need to convert the string into nsdata, and then you need to extract the character information in this nsdata (used as a GET request parameter ). At this time, you are dumb. You find that the encrypted nsdata cannot be converted to an nsstring. What else can be used as the GET request parameter?

Today, we provide you with a binary file that is used to convert any encoding into text, and can convert this text into a binary file category in turn.

 

Provide source code directly:

Nsdata + binary. h and nsdata + binary. m

/// Nsdata + binary. h /// http://home.cnblogs.com/u/YouXianMing///// copyright (c) 2014 y. x. all rights reserved. // # import <Foundation/Foundation. h> @ interface nsdata (Binary) // convert unrecognized binary files into identifiable text files-(nsstring *) transformtovisiblestring; @ end
/// Nsdata + binary. M /// http://home.cnblogs.com/u/YouXianMing///// copyright (c) 2014 y. x. all rights reserved. // # import "nsdata + binary. H "@ implementation nsdata (Binary)-(nsstring *) transformtovisiblestring {If (Self) {nsstring * strret = @" "; char * pbuff = (char *) [self bytes]; for (INT I = 0; I <self. length; I ++) {strret = [strret stringbyappendingformat: @ "% 02x", pbuff [I] & 0xff] ;}return strret ;}else {return nil ;}} @ end

Nsstring + binary. h and nsstring + binary. m

/// Nsstring + binary. h /// http://home.cnblogs.com/u/YouXianMing///// copyright (c) 2014 y. x. all rights reserved. // # import <Foundation/Foundation. h> @ interface nsstring (Binary) // convert the string to an unidentifiable binary file-(nsdata *) transformtobinarydata; @ end
/// Nsstring + binary. M /// http://home.cnblogs.com/u/YouXianMing///// copyright (c) 2014 y. x. all rights reserved. // # import "nsstring + binary. H "@ implementation nsstring (Binary)-(nsdata *) transformtobinarydata {If (Self) {// convert a string to an unrecognized binary file static unsigned char _ map_ch2hex [] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0, 0, 0, 0, 0, 0, 0 ,//:,;, <, =,> ,?, @, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,}; unsigned char * bytes = (unsigned char *) malloc (self. length + 1) * sizeof (unsigned char); [[self uppercasestring] getcstring :( char *) bytes maxlength: Self. length + 1 encoding: nsutf8stringencoding]; unsigned char * P1 = bytes, * P2 = bytes; unsigned long n = self. length/2; for (INT I = 0; I <n; I ++) {* P1 = _ map_ch2hex [* P2-'0'] * 0x10 + _ map_ch2hex [* (P2 + 1)-'0']; P1 ++; p2 + = 2;} nsdata * todata = [nsdata datawithbytes: bytes length: N]; return todata;} else {return nil;} @ end

The core source code is as follows:

Note:

Why don't we directly provide various encryption and decryption algorithms with ready-made source code? In fact, I only provide you with a tool to convert a binary file encoded in any way into a text file, and convert the text into a binary file category in turn. Follow the guidelines in Object-Oriented DesignSingle Responsibility PrincipleIn order to be modular, let everyone better encapsulate it. As for how to encapsulate those encryption and decryption algorithms, It is physical strength. What I provide is one of the core components that you can use comfortably.

 

 

 

 

 

 

 

Encryption and decryption are no longer your nightmare

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.