aeskey.js 655 B

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