How can I compute a SHA-2 (ideally SHA 256 or SHA 512) hash in iOS?

后端 未结 6 1945
臣服心动
臣服心动 2020-11-27 10:32

The Security services API doesn\'t appear to allow me to compute a hash directly. There are plenty of public domain and liberally licensed versions available, but I\'d rathe

6条回答
  •  春和景丽
    2020-11-27 11:06

    + (NSData *)sha256DataFromData:(NSData *)data {
        unsigned char result[CC_SHA256_DIGEST_LENGTH];
        CC_SHA256([data bytes], (int)[data length], result);
        return [NSData dataWithBytes:result length:CC_SHA256_DIGEST_LENGTH];
    }
    

提交回复
热议问题