Objective-C需要java等效的SHA512

Objective-C需要java等效的SHA512,objective-c,Objective C,由于我只是这个领域的初学者,这个问题可能看起来很琐碎,但请原谅。我有如下Java代码: String passwordSalt = "somesalt"; byte[] bsalt = base64ToByte(passwordSalt); byte[] thePasswordToDigestAsBytes = ("somepassword").getBytes("UTF-8"); System.out.println("----------------

由于我只是这个领域的初学者,这个问题可能看起来很琐碎,但请原谅。我有如下Java代码:

String passwordSalt = "somesalt";
       byte[] bsalt = base64ToByte(passwordSalt);
       byte[] thePasswordToDigestAsBytes = ("somepassword").getBytes("UTF-8");
       System.out.println("------------------------------"+passwordSalt);
       MessageDigest digest = MessageDigest.getInstance("SHA-512");
        digest.reset();
        digest.update(bsalt);
        byte[] input = digest.digest(thePasswordToDigestAsBytes);
        System.out.println("------------------------------"+byteToBase64(input));
我希望在Objective-C中实现同样的目标,并使用以下代码:

NSData *saltdata = [Base64 decode:@"some base64 encoded salt"];
NSString *passwordDgst;
passwordDgst = @"somepassword";
NSData *input = [passwordDgst dataUsingEncoding: NSUTF8StringEncoding];
    unsigned char hash[CC_SHA512_DIGEST_LENGTH];
    CC_SHA512_CTX context;
    CC_SHA512_Init(&context);
    CC_SHA512_Update(&context, [saltdata bytes], (CC_LONG)[saltdata length]);
    CC_SHA512_Update(&context, [input bytes], (CC_LONG)[input length]);
    CC_SHA512_Final(hash, &context);
    input = [NSMutableData dataWithBytes:(const void *)hash    length:sizeof(unsigned char)*CC_SHA512_DIGEST_LENGTH];
    passwordDgst = [input encodeBase64WithNewlines:NO];
但这似乎生成了与Java代码不同的散列?为什么呢?有人能向我澄清一下吗?提前感谢:)

重复。