Objective C SHA512 hash of two NSData

一世执手 提交于 2019-12-03 21:28:27

I haven’t run this code and compared it with a Java implementation but it should work:

@implementation NSData (CommonDigest)

- (NSData *)SHA512HashWithSalt:(NSData *)salt {
    unsigned char hash[CC_SHA512_DIGEST_LENGTH];
    CC_SHA512_CTX context;
    CC_SHA512_Init(&context);
    if ([salt length]) {
        CC_SHA512_Update(&context, [salt bytes], (CC_LONG)[salt length]);
    }
    CC_SHA512_Update(&context, [self bytes], (CC_LONG)[self length]);
    CC_SHA512_Final(hash, &context);
    return [NSData dataWithBytes:hash length:CC_SHA512_DIGEST_LENGTH];
}

@end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!