$password='abc';
$salt='123';
$salted=$password.'{'.$salt.'}';
$digest = hash('sha256', $salted,true); $iterations=5000;
for ($i = 1; $i < $iterations; ++$i) {
$digest = hash('sha256', $digest.$salted, true);
}
echo base64_encode($digest) ;
怎么转成java $digest = hash('sha256', $digest.$salted, true); 这一行 我的java生成的和php的不一样
javaj
String password = "abc";
String salt = "123";
String salted = password + "{" + salt + "}"; byte[] digest = Decript.MessageDigestSHA256by(salted); for (int i = 1; i < 5000; ++i) { digest = Decript.MessageDigestSHA256by(digest + salted);
}
String _digest = (new sun.misc.BASE64Encoder()).encode(digest);
public static byte[] MessageDigestSHA256by(String val) { byte[] by = null; try { MessageDigest md = MessageDigest.getInstance("SHA-256"); by = md.digest(val.getBytes()); } catch (Exception e) { e.printStackTrace(); } return by; }
|