Swift development Tutorial--How to encrypt a string MD5

Source: Internet
Author: User

in the SWIFT project to build a random objective-c class, you will be prompted to generate a Bridging-header, click Yes, and then delete the Objective-c class just created, leaving only [project name]-bridging-header.h file.
in the [project name]-bridging-header.h file write:
#import <CommonCrypto/CommonDigest.h>

Then write a function that generates MD5:

class func md5string (str:string),string{

var cStr = (strasnsstring). utf8string

var buffer =unsafemutablepointer<UInt8 . Alloc (+)

cc_md5(cStr, (cc_long) (strlen(CSTR)), buffer)

var md5string:nsmutablestring =nsmutablestring( );

for var i = 0; i < ; ++i{

md5string. AppendFormat ("%x2", buffer)

}

free(buffer)

returnString(md5string);

}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Swift development Tutorial--How to encrypt a string MD5

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.