You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to generate an hmac from my payload and key. The following NodeJS code does this successfully:
var crypto = require('crypto')
function generateSignature(applicationKey, payload) {
if (payload === undefined) {
return ""
}
var strPayload = JSON.stringify(payload)
var buffPayload = new Buffer(strPayload)
var buffKey = new Buffer(applicationKey, 'hex')
var hmac = crypto.createHmac('md5', buffKey);
hmac.write(buffPayload);
hmac.end()
var signature = hmac.read().toString('hex')
return signature
}
exports.generateSignature = generateSignature
In order to use this in my load test, I browserify this NodeJS file with:
browserify b.js --standalone sign > sign.js
Then, in my test I would require the browserified module: var sign = require('./sign.js')
And call:
var signature = sign.generateSignature(appKey, customerUpdatePayload)
However, when I run the JS file with k6, I get the following error:
TypeError: Value is not an object: undefined
referring to the browserified sign.js file.
This seems like a fairly common use case and I was wondering if I'm doing something wrong here?
Any advice would be very welcome. Thank you!
The text was updated successfully, but these errors were encountered:
alexgo84
changed the title
Error on using 'crypt' functions inside browserified NodeJS module
Error on using 'crypto' functions inside browserified NodeJS module
Oct 25, 2018
importing nodejs "crypto" is not possible. Maybe in the future we will decide that instead of "k6/crypto" being a totally new implementation we are going to reimplement "crypto" from nodejs ... but this won't happen soon IMO.
I am trying to generate an hmac from my payload and key. The following NodeJS code does this successfully:
In order to use this in my load test, I browserify this NodeJS file with:
Then, in my test I would require the browserified module:
var sign = require('./sign.js')
And call:
However, when I run the JS file with k6, I get the following error:
referring to the browserified
sign.js
file.This seems like a fairly common use case and I was wondering if I'm doing something wrong here?
Any advice would be very welcome. Thank you!
The text was updated successfully, but these errors were encountered: