ios objective c sha256 해쉬 sha 512 함수
#import <CommonCrypto/CommonDigest.h>
-(NSString*) sha256:(NSString *)clear{
const char *s=[clear cStringUsingEncoding:NSASCIIStringEncoding];
NSData *keyData=[NSData dataWithBytes:s length:strlen(s)];
uint8_t digest[CC_SHA256_DIGEST_LENGTH]={0};
CC_SHA256(keyData.bytes, keyData.length, digest);
NSData *out=[NSData dataWithBytes:digest length:CC_SHA256_DIGEST_LENGTH];
NSString *hash=[out description];
hash = [hash stringByReplacingOccurrencesOfString:@" " withString:@""];
hash = [hash stringByReplacingOccurrencesOfString:@"<" withString:@""];
hash = [hash stringByReplacingOccurrencesOfString:@">" withString:@""];
return hash;
}
-(NSString *)createSHA512:(NSString *)string
{
const char *cstr = [string cStringUsingEncoding:NSUTF8StringEncoding];
NSData *data = [NSData dataWithBytes:cstr length:string.length];
uint8_t digest[CC_SHA512_DIGEST_LENGTH];
CC_SHA512(data.bytes, data.length, digest);
NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA512_DIGEST_LENGTH * 2];
for(int i = 0; i < CC_SHA512_DIGEST_LENGTH; i++)
[output appendFormat:@"%02x", digest[i]];
return output;
}
'ios 뽀개기 > objective-c' 카테고리의 다른 글
ios filemanager 관련 모듈 - 저장 삭제 이동 (0) | 2018.12.07 |
---|---|
ios 사이드 메뉴 (0) | 2018.12.05 |
ios 카메라를 만드는 두가지 방법 - 설명 (0) | 2018.12.04 |
ios 카메라를 만드는 두가지 방법 2 (0) | 2018.12.03 |
objective c nsoperation 예제 (1) | 2018.11.27 |
댓글