如何与Java和PHP兼容相同的密码? [英] How to have the same password compatible with both java and php?

查看:395
本文介绍了如何与Java和PHP兼容相同的密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用PHP的crypt函数来散列密码。
例如:

I have used php crypt function to hash password. For example:

<?php

$hash = '$2y$08$ffWmSGZOM5pNJpHNvpqMa.z01BL25WGoXViaWYhxS0WRaftgAxhkC';
$test = crypt("test", $hash);
$pass = $test == $hash;

echo "Test for functionality of compat library: " . ($pass ? "Pass" : "Fail");
echo "\n";

现在:
如果我使用PHP bcrypt passowrd_hash()函数,我得到这个输出如下:

NOW: If i use php bcrypt passowrd_hash() function i get this following output:

密码:test

使用passowrd_hash(bcrypted密码)为:
    $ 2Y $ 08 $ ffWmSGZOM5pNJpHNvpqMa.z01BL25WGoXViaWYhxS0WRaftgAxhkC

bcrypted password using passowrd_hash() is : $2y$08$ffWmSGZOM5pNJpHNvpqMa.z01BL25WGoXViaWYhxS0WRaftgAxhkC

现在我想在Android的Java中的相同的输出。
我的问题是:

Now i want to have the same output in Android Java. My questions are:


  1. 我怎样才能做到这一点?

  2. 有没有在Android中Java中的所有类文件或默认的功能,这样我可以用它来实现这一目标?

  3. 请我必须写一个自定义函数来实现这一目标?

我也想用java解密密码。

I also want to decrypt the password using java.

与诸如任何答案将是AP preciated。提前感谢所有。

Any answer with example will be appreciated. Advance thanks to all.

推荐答案

如果你坚持使用 bcrypt 在Java中。试试这个, jBCrypt

If you insist of using bcrypt in Java. Try this, jBCrypt.

这篇关于如何与Java和PHP兼容相同的密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆