我正在做一个文件上传工作.我想生成SHA256和CRC32哈希.任何人都可以帮助我如何生成这些哈希?我想让它适用于iOS.
zap*_*aph 33
SHA256在CommonCrypto中可用.CRC32不是散列,它是循环冗余校验.
示例代码:
#import <CommonCrypto/CommonDigest.h>
NSData *dataIn = [@"Now is the time for all good computers to come to the aid of their masters." dataUsingEncoding:NSASCIIStringEncoding];
NSMutableData *macOut = [NSMutableData dataWithLength:CC_SHA256_DIGEST_LENGTH];
CC_SHA256(dataIn.bytes, dataIn.length, macOut.mutableBytes);
NSLog(@"dataIn: %@", dataIn);
NSLog(@"macOut: %@", macOut);
Run Code Online (Sandbox Code Playgroud)
NSLog输出:
dataIn:<4e6f7720 69732074 68652074 696d6520 666f7220 616c6c20 676f6f64 20636f6d 70757465 72732074 6f20636f 6d652074 6f207468 65206169 64206f66 20746865 6972206d 61737465 72732e>
macOut:<53f89cf6 7ebfbe56 89f1f76a 3843dfd1 09d68c5b a938dcd2 9a12004e 108260cb>
| 归档时间: |
|
| 查看次数: |
18191 次 |
| 最近记录: |