Can you get this same Java SHA-1 in PHP please?

前端 未结 3 1556
谎友^
谎友^ 2021-01-06 03:28

I find myself in a need to change website platforms from Java to PHP but I\'d like to keep all my user\'s passwords...

I had this code do the password hashing prior

3条回答
  •  春和景丽
    2021-01-06 04:07

    PHP's sha1() encodes each byte of the output as hexadecimal by default, but you can get the raw output by passing true as the second argument:

    $digest = sha1($password, true); // This returns the same string of bytes as md.digest()
    

    Then pass the digest to base64_encode and you are done:

    base64_encode(sha1($password, true));
    

    This returns the exact same SHA-1 hash as your java code.

提交回复
热议问题