Node RSA and Firebase Function - Why the Error: DSO support routines:win32_load: could not load?

1.1k views Asked by At

I am using the node-rsa package in a firebase function , but when I run the emulator to test the function, I get the following error:

Error: error:25078067:DSO support routines:win32_load:could not load the shared library at Sign.sign (node:internal/crypto/sig:131:29) at Scheme.sign (C:\Users\XXX\Desktop\work\XXX\functions\node_modules\node-rsa\src\schemes\pkcs1.js:154:27) at RSAKey.module.exports.Key.RSAKey.sign

I have no idea where to go from here and how to troubleshoot this. Here's my firebase cloud function:

import NodeRSA from 'node-rsa'
import * as functions from 'firebase-functions'

const keyData = {
  consumerId: '<ID REMOVED>',
  privateKey: `-----BEGIN RSA PRIVATE KEY-----
  <PRIVATE KEY REMOVED>
  -----END RSA PRIVATE KEY-----`,
  keyVer: 1
  //   impactId: "YOUR IMPACT AFFILIATE ID" // not required
}

const generateWalmartHeaders = () => {
  const { privateKey, consumerId, keyVer } = keyData
  const hashList = {
    'WM_CONSUMER.ID': consumerId,
    'WM_CONSUMER.INTIMESTAMP': Date.now().toString(),
    'WM_SEC.KEY_VERSION': keyVer
  }

  const sortedHashString = `${hashList['WM_CONSUMER.ID']}\n${hashList['WM_CONSUMER.INTIMESTAMP']}\n${hashList['WM_SEC.KEY_VERSION']}\n`
  const signer = new NodeRSA(privateKey, 'pkcs1')
  const signature = signer.sign(sortedHashString)
  const signatureEnc = signature.toString('base64')

  return {
    'WM_SEC.AUTH_SIGNATURE': signatureEnc,
    'WM_CONSUMER.INTIMESTAMP': hashList['WM_CONSUMER.INTIMESTAMP'],
    'WM_CONSUMER.ID': hashList['WM_CONSUMER.ID'],
    'WM_SEC.KEY_VERSION': hashList['WM_SEC.KEY_VERSION']
  }
}

export const getProductById = functions.https.onRequest(async (req, res) => {
  const options = {
    method: 'GET',
    headers: generateWalmartHeaders()
  }

  try {
    const response = await fetch(
      `https://developer.api.walmart.com/api-proxy/service/affil/product/v2/items/4837473`,
      options
    )
    const product = await response.json()
    console.log('product?', product)
    res.send(product)
  } catch (error) {
    console.log('error in walmartjs', error)
    res.status(500).send(error)
  }
})

Anyone got any idea on why I am getting that error?

1

There are 1 answers

0
IOSupport On

You should NOT copy -----BEGIN RSA PRIVATE KEY----- and -----END RSA PRIVATE KEY----- these 2 lines as part of private key.
Please kindly remove these 2 lines as part of private key

enter image description here

Regards,
Firdos
IOSupport