crypto.scrypt -> createDecipheriv -> error. NodeJS

281 Views Asked by At

I enountered a problem where I was attempting to derive a 256bit key from an input password in hopes to use it with crypto.createCipheriv/createDecipheriv. This gives me the following error: [ERR_INVALID_ARG_TYPE]: the "key" argument must be of type string or an instance of Buffer, TypedArray, DataView, or KeyObject. Recieved undefined I am not sure why... this.key = crypto.scrypt(this.passphrase, 'baewithsalt',256, (err)=>{if(err) throw err;}); when being used in... this.decipher = crypto.createDecipher(this.algorithm, this.key, this.iv); is telling me the key is undefined. I have these variables initialized just above that... this.passphrase ='whatever'; this.algorithm = 'aes-256-cbc'; this.iv =crypto.randomBytes(16); what am I doing wrong and why can't I use scrypt to generate a key from a password for cipheriv/decipheriv? I apologize if the format may be slightly off, my internet is out and I typed it through my phone.

0

There are 0 best solutions below