Using OpenSSL under iOS8.1

Source: Internet
Author: User
Tags openssl library uikit

First, download the OpenSSL source code, compiled into a callable library

In order to save everyone's trouble, we provide a ready-made OpenSSL library for everyone: Http://pan.baidu.com/s/1hqpbKpA

Unzip, you can see the Include folder and LIBCRYPTO.A, libssl.a two files.

Ii. New Project OpenSSL

Copy the Include folder to the project root directory,

Copy libcrypto.a and LIBSSL.A to the project root directory

Add the above files to your project.

The final project structure is as follows:

Third, set the value of "Header Search Paths" to/users/huangzhiming/desktop/work/openssl/openssl/include

Set the value of "Valid architectures" to armv7/armv7s

Iv. writing code.

#import <UIKit/UIKit.h>

#import <openssl/md5.h>

void Md5 (NSString *);

int main (int argc, char *argv[]) {

NSAutoreleasePool * Pool = [[NSAutoreleasePool alloc] init];

Md5 (@ "12345");

int retVal = Uiapplicationmain (argc, argv, nil, nil);

[Pool release];

return retVal;

}

void Md5 (NSString * string) {

Input parameter 1: String to generate the MD5 value, nsstring-->uchar*

unsigned char *INSTRG = (unsigned char *) [[string datausingencoding:nsasciistringencoding] bytes];

Input parameter 2: string length

unsigned long lngth = [string length];

Output Parameter 3: MD5 value to return, md5_digest_length to 16bytes, bits

unsigned char result[md5_digest_length];

A temporary nsstring variable used to assemble uchar* into a string that can be displayed: 2 characters selector byte of 16 binary number

nsmutablestring *OUTSTRG = [nsmutablestring string];

Call the OpenSSL function

MD5 (INSTRG, lngth, result);

unsigned int i;

for (i = 0; i < md5_digest_length; i++)

{

[OUTSTRG AppendFormat: @ "%02x", Result[i]];

}

NSLog (@ "Input string:%@", string);

NSLog (@ "md5:%@", OUTSTRG);

}

Run, you can see the output as follows:

Input string:12345

md5:827ccb0eea8a706c4c34a16891f84e7b

Using OpenSSL under iOS8.1

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.