-(NSString*) sha256:(NSString *)text{ const char *s=[text 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; }
上のソースを使う為にimportを追加する必要があります。
#import <CommonCrypto/CommonHMAC.h>
0 件のコメント:
コメントを投稿