|
- //
- // Util.m
- // goodpk
- //
- // Created by 歐特儀 on 2020/6/19.
- // Copyright © 2020 Altob. All rights reserved.
- //
-
- #import "Util.h"
- #include <CommonCrypto/CommonDigest.h>
-
- @implementation Util
-
- +(NSString*)sha256HashFor:(NSString*)input
- {
- const char* str = [input UTF8String];
- unsigned char result[CC_SHA256_DIGEST_LENGTH];
- CC_SHA256(str, strlen(str), result);
-
- NSMutableString *ret = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH*2];
- for(int i = 0; i<CC_SHA256_DIGEST_LENGTH; i++)
- {
- [ret appendFormat:@"%02x",result[i]];
- }
-
- return [ret substringToIndex:10];
- }
-
- @end
|