I am integrating the same login functionality using same database on java and php platforms but having some problem in password algorithms.
Here is my java code:-
public static String encryptPassword(String strToEncrypt,String saltToEncrypt)
{
String encryptedString = "";
String stringToEncrypt = "";
byte[] encodedValue;
stringToEncrypt = strToEncrypt + saltToEncrypt;
encodedValue = Base64.encodeBase64(DigestUtils.sha256(stringToEncrypt
.getBytes()));
encryptedString = new String(encodedValue);
return encryptedString;
}
Here is my PHP code:-
function encryptPassword($strToEncrypt, $saltToEncrypt)
{
$stringToEncrypt = $strToEncrypt.$saltToEncrypt;
$encodedValue = base64_encode(hash('sha256', $stringToEncrypt));
return $encodedValue;
}
Ideally, both of these functions should generate the same encrypted string but these are giving different results. What is wrong with my code? Please advise.