duanlang0025 2014-08-17 12:29
浏览 62

使用没有crypt的Blowfish密码()

I'm actually, for testing and challenging purposes, trying to write a little password encryption system.

I've read about blowfish algorithm and I'm pretty interested in it, After reading the wikipedia page about it, I think the algorithm ould be the one I look for. But php's crypt() function do all the "dirty job" for you. From what I read in wikipedia, Blowfish is a symetric key cypher, meaning you can encrypt it and decrypt it with the same key (correct me if I'm wrong), So I'm looking for a way, in php, that allows you to use blowfish as his most primitive form : something like :

blowfis($data, $key, $rounds);

I'm pretty sure library like that exists but after some googling I didn't found anyone. So is such a lib exist? Or have I to write this function myself, wich is, I'm sure, really complex?

So my question is: Is it possible to use blowfish without crypt()? If it is, How? With a specific library? Or with native Php functions?

  • 写回答

1条回答 默认 最新

  • duanao2688 2014-08-17 12:58
    关注

    If your PHP version is >= 5.5 consider using password_hash and password_verify methods to encrypt and validate passwords. Also password_hash is compatible with crypt().

    Try this:

    $options = array(
        'salt' => 'Your very secret static salt here',
        'cost' => 12,
        );
    $pass = password_hash("passwordProvided", PASSWORD_BCRYPT, $options);
    

    At this point, $pass variable holds hashed version of passwordProvided and seems like something like that:

    $2y$10$WW91ciB2ZXJ5IHNlY3Jld.w58GyS1ueaPDQ.93.N2PWoiRvJ12GiK
    

    To verify password;

    $hashed = '$2y$10$WW91ciB2ZXJ5IHNlY3Jld.w58GyS1ueaPDQ.93.N2PWoiRvJ12GiK';
    
    if(password_verify('passwordProvided', $hashed)) {
        // Password is valid.
    }
    

    Note: Increasing the cost parameter by one, doubles the needed time to calculate the hash value.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog