IOS --- sha1 Encryption

Source: Internet
Author: User
Tags sha1 sha1 encryption

IOS --- sha1 Encryption

 

The sha1 encryption algorithm written in the OC language can be searched on the Internet at Will (as shown below), but I have to say that some people are not responsible and did not remind everyone to import necessary system header files, this leads to errors.

+ (NSString *) sha1 :( NSString *) inputStr {

Const char * cstr = [inputStr cStringUsingEncoding: NSUTF8StringEncoding];

NSData * data = [NSData dataWithBytes: cstr length: input. length];

 

Uint8_t digest [CC_SHA1_DIGEST_LENGTH];

 

CC_SHA1 (data. bytes, (unsigned int) data. length, digest );

 

NSMutableString * outputStr = [NSMutableString stringWithCapacity: CC_SHA1_DIGEST_LENGTH * 2];

 

For (int I = 0; I

[OutputStr appendFormat: @ % 02x, digest [I];

}

Return outputStr;

}

 

Before using the sha1 encryption algorithm, we need to # import

Hope that the majority of bloggers can write more carefully in the future. Thank you!

 

In addition to sha1, there are also md5, or their combination with base64! This is commonly used, and of course there are many better!

 

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.