Code snippets:
php:
$shaVal = '59bc125840733ea828f42e276661b01e177f1414';
$enc = base64_encode(pack('H*', $shaVal));
echo $enc;
//prints => WbwSWEBzPqgo9C4nZmGwHhd/FBQ=
and in Javascipt I used buffer
npm module
let Buffer = require('buffer').Buffer;
let shaVal = '59bc125840733ea828f42e276661b01e177f1414';
//function similar to php's pack() and returns binary data
let bData = Buffer.from(shaVal, 'hex').toString();
console.log('bData ', bData)
//encode with base64
let val64 = Buffer.from(bData, 'binary').toString('base64');
console.log('base 64 encode ', val64)
//prints => Wf0SWEBzPv0o/S4nZmH9Hhd/FBQ=
How can I get the exact same output printed by php?
Note: Both options showing binary data as Y�X@s>�(�.'fa�