简体   繁体   中英

Message Digest in Objective-C

as I'm a newbie in this field the question may seem to be so stupid, but please forgive me. I want to achieve SHA-512 in Objective-C for an equivalent Java code..Here is the Java Code :

String passwordSalt = "Somesalt";
byte[] bsalt=base64ToByte(passwordSalt);
byte[] passwordToDigestAsBytes=("somepassword").getBytes("UTF-8");

MessageDigest digest = MessageDigest.getInstance("SHA-512");
digest.reset();
digest.update(bsalt);
byte[] = input digest.digest(passwordToDigestAsBytes);

I'm using CC_SHA512 for digest function...but what I need to do for digest.update(bsalt) part? how can I achieve the same functionality in Objective-C?

I'm not familiar with Java's MessageDigest object, but it looks like it's just prepending the salt before the data, which is a very normal way to process this kind of data. So you'd just call CC_SHA512_Update() twice. Once with the salt, and then a second time with the password data. Then you'd call CC_SHA512_Final() to fetch the result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM