PHP's hash() in Java -
i trying java generate same hash string php's hash
algorithm does.
i have come close enough:
hash('sha512', 'password');
outputs:
b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86
java code:
public static void main(string[] args) { hash("password"); } private static string hash(string salted) { byte[] digest; try { messagedigest mda = messagedigest.getinstance("sha-512"); digest = mda.digest(salted.getbytes("utf-8")); } catch (exception e) { digest = new byte[]{}; } string str = ""; (byte adigest : digest) { str += string.format("%02x", 0xff & adigest); } return str; }
this outputs same.
my problem when use third argument within php's hash
function. on php's site it's described following:
raw_output when set true, outputs raw binary data. false outputs lowercase hexits.
i not quite sure how implement parameter. think question be, how convert string
object binary string
object? currently, running php generates following: http://sandbox.onlinephpfunctions.com/code/a1bd9b399b3ac0c4db611fe748998f18738d19e3
this should reproduce outcome link:
string strbinary = null; try { strbinary = new string(digest, "utf-8"); } catch (unsupportedencodingexception e) { }
and you'll need these imports @ top of file:
import java.nio.charset.charset; import java.io.unsupportedencodingexception;
i hope understood issue correctly.
Comments
Post a Comment