网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

iOSSDK计算SHA1和MD5

How to get md5 and SHA1 in objective c (iOS sdk)

Calculating the md5 and sha1 hash in iOS sdk is pretty simple -

成都创新互联公司于2013年成立,是专业互联网技术服务公司,拥有项目成都网站建设、成都网站制作网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元芙蓉做网站,已为上家服务,为芙蓉各地企业和个人服务,联系电话:18982081108

Step 1 – The very first thing you need to do is import CommonCrypto’s CommonDigest.h


?

戴维营教育代码
1
#import


Step 2 – Here is the real code for calculating SHA1 and MD5 hash -

SHA1 -


?

戴维营教育代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
-(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 -

?

戴维营教育代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
- (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/

iOS SDK计算SHA1和MD5收藏0


当前标题:iOSSDK计算SHA1和MD5
网址分享:http://bjjierui.cn/article/gjpodo.html

其他资讯