iOS version of RC4-BASE64 encryption decryption

Source: Internet
Author: User
Tags base64 cdata openssl library

On the internet to find a lot of RC4 and decryption, OC write encryption is mainly http://www.cocoachina.com/bbs/read.php?tid-77608.html this article. After I used, and our PHP can not correspond, he encrypted after I decrypt the wrong, I encrypt his decryption is not right. So, I wrote it myself again.

1. First, download a OpenSSL library and put the library on the desktop

2. Create a new project and import two libraries in Lib-ios: LIBCRYPTO.A and LIBSSL.A, open Project, Build Setting->header Search Paths add Field/users/xxxx/desktop/ Openssl-master/include-ios,library Search Paths Add field $ (project_dir)/project name/folder name;

3. Import zhyrc4.c, Zhyrc4.h, base64.c, Base64.h.

4. Use: Import header file # include "Zhyrc4.h",

Encryption

+ (NSString *) Encode: (NSString *) data{
Char *pwd = "@ndroid!os";
const char * cData = [data utf8string];

char *base64_data = NULL;
Zhyencode (PWD, CDATA, strlen (CDATA), &base64_data);

NSString * str = [NSString stringwithutf8string:base64_data];

if (base64_data) {
Free (base64_data);
Base64_data = NULL;
}

return str;
}

+ (NSString *) decode: (NSString *) data{
Char *pwd = "@ndroid!os";

const char * cData = [data utf8string];

Char *data1=null;

Zhydecode (pwd, CData, &data1);

NSString * str = [NSString stringwithutf8string:data1];

if (data1) {
Free (DATA1);
Data1 = NULL;
}

return str;
}

That's it. RC4 plus decryption are the same method, if you do not need base64 encryption, in ZHYRC4.C, zhyrc4.h change on the line, so easy.

File is too big, give a link: Link: http://pan.baidu.com/s/1nvpgkdz Password: n82a

iOS version of RC4-BASE64 encryption decryption

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.