Search code examples
base64sha1cryptojs

PHP Equivalent of sha1.toString(CryptoJS.enc.Base64)


I am converting a JS script into PHP. The script uses the CryptoJS library and generates a hash using the following line:

var sha1 = CryptoJS.SHA1("message");
var sig = sha1.toString(CryptoJS.enc.Base64);

I have tried this php code

$sha1 = sha1("message");
$sig = base64_encode($sha1);

But the signature isn't the same, it's longer in php.

Your help is very much appreciated and needed !

John


Solution

  • Ok I just needed to set $raw_output to true in the sha1 function !

    $sha1 = sha1("message", true);
    

    Now I look silly