Answer the question
In order to leave comments, you need to log in
Why don't SHA-256 methods match java, python, php?
Hello, please tell me how to properly implement password hashing in python. When everything is correct in Java and Php.
The bottom line is that java and php have the same hashes, but in python with the same value: "111111" - it gives a different hash
Code in java:
public static String encodePassword(String password) {
try {
MessageDigest messageDiegest = MessageDigest.getInstance("SHA-256");
messageDiegest.update(password.getBytes("UTF-8"));
return Base64.encodeToString(messageDiegest.digest(), false);
}
catch (NoSuchAlgorithmException e) {
System.out.println("Exception while encoding password");
throw new Error(e);
}
catch (UnsupportedEncodingException e) {
System.out.println("Exception while encoding password");
throw new Error(e);
}
}
$password = trim($pass1);
$password = base64_encode(sha1($password, true));
digest = hmac.new(bytes(ps, 'UTF-8'), msg=None, digestmod=hashlib.sha256).digest()
signature = base64.b64encode(digest).decode()
print(signature)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question