I'm using NodeJS's crypto library and Crypto-JS. From the crypto library, I am generating ECDH client and generating the keys from which to use its private key for AES encryption with Crypto-JS in the future. the AES encryption function requires you to pass in a private key, which was done but it would not take it as a Buffer. It works when I use the hex string version, but I'm naïve and unsure if this has the strength of the ECDH private key I encoded to hex string.
Snippets of code to analyze (assume inData variable is a string):
var privBIN = programData.volatile.modularVariables.key; //some ECDH secret hex encoded
var inData = 'something';
var cipherInData = programData.volatile.modularVariables.cipherText(inData,privBIN);
key and value in programData object:
cipherText: (content, key)=>{console.log(`content: ${content}`); console.log(`key: ${key}`); return cryptojs.AES.encrypt(content,key).toString()},
The above ciphers the text in AES fine, but substitute priveBIN for:
var privBIN = Buffer.from(programData.volatile.modularVariables.key,programData.volatile.modularVariables.encoding.hex);
and suddenly it gives me the following error (I included where in crypto-js it has issues):
(node:15028) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '0' of undefined
at Object.xorBlock (C:\Users\Mickell\Desktop\CPHR\node_modules\crypto-js\cipher-core.js:371:44)
at Object.processBlock (C:\Users\Mickell\Desktop\CPHR\node_modules\crypto-js\cipher-core.js:314:27)
at Object._doProcessBlock (C:\Users\Mickell\Desktop\CPHR\node_modules\crypto-js\cipher-core.js:486:25)
at Object._process (C:\Users\Mickell\Desktop\CPHR\node_modules\crypto-js\core.js:632:27)
at Object._doFinalize (C:\Users\Mickell\Desktop\CPHR\node_modules\crypto-js\cipher-core.js:501:46)
at Object.finalize (C:\Users\Mickell\Desktop\CPHR\node_modules\crypto-js\cipher-core.js:163:44)
at Object.encrypt (C:\Users\Mickell\Desktop\CPHR\node_modules\crypto-js\cipher-core.js:685:41)
at Object.encrypt (C:\Users\Mickell\Desktop\CPHR\node_modules\crypto-js\cipher-core.js:201:59)
Questions: can someone explain if the hex encoded version of the ECDH client's private key suffices? Or is that completely negligible and its the private key as buffer I should pass in and how? Thank you for your time :).