1 回答
TA贡献1865条经验 获得超7个赞
下面的 2 个示例产生相同的输出:
PHP:
$length = 60;
$salt = "MySalt";
$interation = 10;
$bytes = openssl_pbkdf2("mypasspharse", $salt, $length, $interation, "sha1");
for ($i = 0; $i < 60; $i++)
{
echo dechex(ord($bytes[$i]));
echo '<br>';
}
爪哇:
int length = 60 * 8;
String passphrase = "mypasspharse";
String salt = "MySalt";
int iteration = 10;
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
PBEKeySpec spec = new PBEKeySpec(passphrase.toCharArray(), salt.getBytes("UTF-8"), iteration, length);
byte[] bytes = factory.generateSecret(spec).getEncoded();
for (int i = 0; i < 60; i++) {
System.out.println(Integer.toHexString(bytes[i] & 0xFF));
}
- 1 回答
- 0 关注
- 154 浏览
添加回答
举报