gpt4 book ai didi

iphone - 如何在 ios 中生成 SHA256 和 CRC32

转载 作者:可可西里 更新时间:2023-11-01 03:02:44 25 4
gpt4 key购买 nike

我正在做文件上传工作。我想生成 SHA256 和 CRC32 哈希值。任何人都可以帮助我如何生成这些哈希值?我想让它适用于 iOS。

最佳答案

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);

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>

关于iphone - 如何在 ios 中生成 SHA256 和 CRC32,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9444215/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com