iOS SDK计算SHA1和MD5
How to get md5 and SHA1 in objective c (iOS sdk)
戴维营教育代码 1
戴维营教育代码 0102030405060708091011121314151617
MD5 -
戴维营教育代码 0102030405060708091011121314
Hope it will help someone!!
via:
http://www.makebetterthings.com/ ... bjective-c-ios-sdk/
Calculating the md5 and sha1 hash in iOS sdk is pretty simple -
Step 1– The very first thing you need to do is import CommonCrypto’s CommonDigest.h
?
#import <CommonCrypto/CommonDigest.h>
Step 2– Here is the real code for calculating SHA1 and MD5 hash -
SHA1 -
?
-(
NSString
*) sha1:(
NSString
*)input
{
const
char
*cstr = [input cStringUsingEncoding:
NSUTF8StringEncoding
];
NSData
*data = [
NSData
dataWithBytes:cstr length:input.length];
uint8_t digest[CC_SHA1_DIGEST_LENGTH];
CC_SHA1(data.bytes, data.length, digest);
NSMutableString
* output = [
NSMutableString
stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];
for
(
int
i = 0; i < CC_SHA1_DIGEST_LENGTH; i++)
[output appendFormat:
@"%02x"
, digest[i]];
return
output;
}
MD5 -
?
- (
NSString
*) md5:(
NSString
*) input
{
const
char
*cStr = [input UTF8String];
unsigned
char
digest[16];
CC_MD5( cStr, strlen(cStr), digest );
// This is the md5 call
NSMutableString
*output = [
NSMutableString
stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
for
(
int
i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
[output appendFormat:
@"%02x"
, digest[i]];
return
output;
}
Hope it will help someone!!
via:
http://www.makebetterthings.com/ ... bjective-c-ios-sdk/
收藏0
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。