aeskey.js 588 B

12345678910111213
  1. var shim = require('./shim');
  2. var sha256hash = require('./sha256');
  3. const importGen = async (key, salt, opt) => {
  4. //const combo = shim.Buffer.concat([shim.Buffer.from(key, 'utf8'), salt || shim.random(8)]).toString('utf8') // old
  5. var opt = opt || {};
  6. const combo = key + (salt || shim.random(8)).toString('utf8'); // new
  7. const hash = shim.Buffer.from(await sha256hash(combo), 'binary')
  8. return await shim.subtle.importKey('raw', new Uint8Array(hash), opt.name || 'AES-GCM', false, ['encrypt', 'decrypt'])
  9. }
  10. module.exports = importGen;