我在Java中有两种方法,但我想在php中做同样的方法。我绝对不了解php。我该怎么做?
方法1:
public static String encyptPassword (String in) throws UnsupportedEncodingException, NoSuchAlgorithmException{
byte[] bytes=in.getBytes("UTF-8");
MessageDigest md=MessageDigest.getInstance(MGF1ParameterSpec.SHA1.getDigestAlgorithm());
md.update(bytes);
byte[] digest=md.digest();
return toHex(digest);
}
方法2:
public static String toHex(byte[] bytes) {
BigInteger bi = new BigInteger(1, bytes);
return String.format("%0" + (bytes.length << 1) + "x", bi);
}
php中的方法(函数?)必须与java中的方法具有相同的结果,因为它是工作和联机登录系统的哈希密码。
我正在尝试大约3个小时,但无法执行或找不到解决方案。我想我阅读了Stack上的所有文章。你能帮助我吗?谢谢。
PHP小提琴-打运行看结果
<?php
$pass = 'MySecretP@55';
$hashed = hash("SHA512", $pass);
echo $hashed;
echo '<hr>' . bin2hex($hashed);
?>
以上是sha512
肯定更好的sha1
,而且具有较高成本的bcrypt被认为是目前最好的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句