Skip to content
Advertisement

PHP’s openssl_sign Equivalent in Node JS

I am (slowly) learning Node JS and trying to use it in place of a PHP script I have. I need to sign a string I have assembled with SSL to pass on to a curl request.

In PHP, this is how I’ve done it:

JavaScript

So I’m trying to generate the evuivalent of $signed_signature, but I’m not sure how to proceed. It seems like Node’s Crypto can do something similar, but its parameters seem different. This is my best guess:

JavaScript

Am I on the right track?

Advertisement

Answer

Using your work as a starting point and doing some minor modifications, the following snippets result in the same signature being printed (base64-encoded):

PHP:

JavaScript

Node JS:

JavaScript

diff-ing the two:

JavaScript

shows the outputs are the same.

I used this resource: iotdb-crypto-example

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement