任何人都可以解决我在iOS中与SHA256相关的问题吗?
#import <CommonCrypto/CommonDigest.h>
NSData *dataIn = [@"XXXXX" dataUsingEncoding:NSASCIIStringEncoding];
NSMutableData *macOut = [NSMutableData dataWithLength:CC_SHA256_DIGEST_LENGTH];
CC_SHA256(dataIn.bytes, dataIn.length, macOut.mutableBytes);
NSLog(@"dataIn: %@", dataIn);
NSLog(@"macOut: %@", macOut);
我得到这样的输出:
2014-10-14 10:46:43.602 sha256[480:70b] dataIn: <416e616e 64>
2014-10-14 10:46:43.604 sha256[480:70b] macOut: <e9fb6a39 4db5ffd6 dba9b31a c7d9a90d 56f90767 afaf1e14 d6dcaa37 db180932>
我真正需要的是我需要删除macOut中的空间。就像这样
答案 0 :(得分:0)
在代码下面添加:
NSString *macOutString = [NSString stringWithFormat:@"%@", macOut];
NSString *encryptedString = [macOutString stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"macOut: %@", encryptedString);
验证加密
答案 1 :(得分:0)
创建NSData,NSString类别在https://github.com/mdznr/iOS-Passcode/blob/master/Passcode/NSString%2Bsha256.m
使用此代码