Closed lu-zen closed 4 years ago
symmetricKeySize
and asymmetricKeySize
props of the KeyObject generated are both undefined.
Running node 12.16.1
https://nodejs.org/docs/latest-v12.x/api/crypto.html#crypto_keyobject_symmetrickeysize
KeyObjects do not have ‘byteLength’ as your code suggests.
I can’t reproduce this report.
require("crypto")
.createSecretKey( Buffer.from("...", "base64") )
.symmetricKeySize // undefined
Wrong code srry. The symmetricKeySize
property is undefined. Running the same code on console returns its size. Any idea?
The code without the property is not using node 12, it’s likely v11 which used symmetricSize property. V11 is not supported by this module tho.
Node 12.16.1. Anyway it's something related to node.
You asked if I had an idea. Your console is node 12, whatever else you run the code in where it doesn’t work is a different version.
Put a console.log(process.versions) in the code and see the difference.
@panva just to check... The func checkKey
receives two args (header, key), but key is passed as the first argument here:
/lib/V2/encrypt.js
payload = checkPayload(payload)
key = checkKey(key) // <<
/lib/V2/help/symmetric_key_check.js
function checkKey (header, key) {
if (!(key instanceof KeyObject)) {
key = createSecretKey(key)
}
if (key.type !== 'secret' || key.symmetricKeySize !== 32) {
throw new TypeError(`${header} secret key must be 32 bytes long symmetric key`)
}
Is this correct? I think this combined to the wrong type of symmetricKeySize popping on vscode confused me :laughing: .
Yes it is used correctly. Your vscode is running node 11, am i right?
Only one node version, latest lts. Idk which lib included node typing. Now it works, just tired I guess. thanks for you help
I don't see what typings have to do with runtime results but okay.
Always get this error even when the secret is long enough.