I need to convert some node.js code to work with PHP. I know there are pack() and unpack() functions and I think they may do the job but I don't know the correct way to do it in PHP. I got this code from https://web-push-book.gauntface.com/ and trying to do this in PHP.
const keyLabel = new Buffer('P-256\0', 'utf8'); // Convert subscription public key into a buffer. const subscriptionPubKey = new Buffer(subscription.keys.p256dh, 'base64'); const subscriptionPubKeyLength = new Uint8Array(2); subscriptionPubKeyLength = 0; subscriptionPubKeyLength = subscriptionPubKey.length; const localPublicKeyLength = new Uint8Array(2); subscriptionPubKeyLength = 0; subscriptionPubKeyLength = localPublicKey.length; const contextBuffer = Buffer.concat([ keyLabel, subscriptionPubKeyLength.buffer, subscriptionPubKey, localPublicKeyLength.buffer, localPublicKey, ]); const nonceEncBuffer = new Buffer('Content-Encoding: nonce\0', 'utf8'); const nonceInfo = Buffer.concat([nonceEncBuffer, contextBuffer]); const cekEncBuffer = new Buffer('Content-Encoding: aesgcm\0'); const cekInfo = Buffer.concat([cekEncBuffer, contextBuffer]);