I was wondering if you guys could help me convert some java code to python. Basically I'm trying to get the same hash output that the java code executes. Currently all I have gotten to (in python) is using the hashlib module converting some string to sha256.
I have tried googling and I have found nothing, friends couldn't help so this is my last resort. Here is the hash outputs I get from python & java. Obviously python being the incorrect hash, and java code being the correct hash.
Java Code Output Hash(correct):
947e238ef26e56d3de2fe2480268c23297d91efe6355b3e5fac0dcf63
Python Code Output Hash(incorrect):
88c5f638b023a5740676960747833fc4eacc20697c92e1b46b0384ebf
The java code hashes a string which gets split into variables, im stuck on the for loop which I'm not able to convert to python. PLEASE take note I am a noob and not that very experienced, thanks :P.
Java CODE:
String pass = "6b508/^!zVl?947e238ef26e56d3de2fe2480268c23297d91efe6355b3e5fac0dcf63";
String secretKey = "Wr79mk1PXFac!#%";
String loginKey = pass.substring(0, 5);
String randomKey = pass.substring(5, 13);
String originalHash = pass.substring(13);
try {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update((loginKey + randomKey + secretKey).getBytes(StandardCharsets.UTF_8));
//obtain hash
byte[] hash = md.digest();
StringBuilder hexString = new StringBuilder();
for (byte aHash : hash) {
String hex = Integer.toHexString(0xff & aHash);
if (hex.length() == 1) hexString.append('0');
hexString.append(hex);
}
String newHash = hexString.toString().substring(0, 56);
if (newHash.equals(originalHash)) {
//hash is right
return true;
}
Python CODE(My attempt to convert):
key = "6b508"
salt = "Wr79mk1PXFac!#%"
rand = "/^!zVl?"
hash = hashlib.sha256(key+rand+salt).hexdigest()
raw_input(hash[0:57])
Any help would be appreciated, thanks.