IOS Base64 Encryption decryption

Source: Internet
Author: User


  • This article reprinted to http://jingyan.baidu.com/article/93f9803fff45c9e0e46f5596.html
  • Download the Gtmbase64.zip library package from the resources address and unzip it to get gtmbase64.h,gtmbase64.m and GTMDefines.h three files.

  • The extracted three files are added to the project.

  • Create a new class of Base64, in the Base64.h Zhongtian four functions:

    + (nsstring*) encodebase64string: (nsstring*) input;

    + (nsstring*) decodebase64string: (nsstring*) input;

    + (nsstring*) Encodebase64data: (nsdata*) data;

    + (nsstring*) Decodebase64data: (nsdata*) data;

    In the base64.m file, implement the above 4 functions:

    + (nsstring*) encodebase64string: (nsstring*) Input {

    Nsdata*data = [InputdataUsingEncoding:NSUTF8StringEncodingallowLossyConversion:YES];

    data = [Gtmbase64encodedata:data];

    nsstring*base64string = [[nsstringalloc]initwithdata:dataencoding:nsutf8stringencoding];

    returnbase64string;

    }

    + (nsstring*) decodebase64string: (nsstring*) Input {

    Nsdata*data = [InputdataUsingEncoding:NSUTF8StringEncodingallowLossyConversion:YES];

    data = [Gtmbase64decodedata:data];

    nsstring*base64string = [[nsstringalloc]initwithdata:dataencoding:nsutf8stringencoding];

    returnbase64string;

    }

    + (nsstring*) Encodebase64data: (nsdata*) Data {

    data = [Gtmbase64encodedata:data];

    nsstring*base64string = [[nsstringalloc]initwithdata:dataencoding:nsutf8stringencoding];

    returnbase64string;

    }

    + (nsstring*) Decodebase64data: (nsdata*) Data {

    data = [Gtmbase64decodedata:data];

    nsstring*base64string = [[nsstringalloc]initwithdata:dataencoding:nsutf8stringencoding];

    returnbase64string;

    }

  • Direct call + (nsstring*) encodebase64string: (nsstring*) input and

    + (nsstring*) decodebase64string: (nsstring*) input can be added and decrypted.

  • You can download the demo from the resources address.

Related Article

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.