diff --git a/src/node/algorithms/shared/AES.js b/src/node/algorithms/shared/AES.js index d1f58f3..c962aef 100644 --- a/src/node/algorithms/shared/AES.js +++ b/src/node/algorithms/shared/AES.js @@ -1,20 +1,24 @@ -var sjcl = require("sjcl"); +var sjcl = require("sjcl"), + crypto = require("crypto"); -function AES_generateKey(noop){ - return; +function AES_generateKey(algorithm){ + return raw_import(crypto.randomBytes(algorithm.length / 8)); } function raw_import(buf){ - return new sjcl.cipher.aes(sjcl.codec.hex.toBits(buf.toString("hex"))); + var key = new sjcl.cipher.aes(sjcl.codec.hex.toBits(buf.toString("hex"))); + key._raw = buf; + return key; } function raw_export(key){ - return key; + return key._raw; } function AES(Algorithm){ Algorithm.formats.raw.import = raw_import; Algorithm.formats.raw.export = raw_export; + Algorithm.generate = AES_generateKey; return; } diff --git a/src/node/generateKey.js b/src/node/generateKey.js index 838ae27..dc5d545 100644 --- a/src/node/generateKey.js +++ b/src/node/generateKey.js @@ -58,7 +58,12 @@ function generateKey(algorithm, exportable, usages, nonce){ //construct the return object from the scaffold Object.keys(_scaf).forEach(function(type){ - _res[_alg.types[type].returnLabel] = new CryptoKey(_key, type, _scaf[type]._exp, _scaf[type]._uses, nonce); + if (_alg.types[type].returnLabel) { + _res[_alg.types[type].returnLabel] = new CryptoKey(_key, type, _scaf[type]._exp, _scaf[type]._uses, nonce); + } + else { + _res = new CryptoKey(_key, type, _scaf[type]._exp, _scaf[type]._uses, nonce); + } }) //special case... ECDH public keys don't have they're own usage, but are still needed as params in deriveKey/Bits