mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00
13 lines
588 B
JavaScript
13 lines
588 B
JavaScript
|
|
var shim = require('./shim');
|
|
var sha256hash = require('./sha256');
|
|
|
|
const importGen = async (key, salt, opt) => {
|
|
//const combo = shim.Buffer.concat([shim.Buffer.from(key, 'utf8'), salt || shim.random(8)]).toString('utf8') // old
|
|
var opt = opt || {};
|
|
const combo = key + (salt || shim.random(8)).toString('utf8'); // new
|
|
const hash = shim.Buffer.from(await sha256hash(combo), 'binary')
|
|
return await shim.subtle.importKey('raw', new Uint8Array(hash), opt.name || 'AES-GCM', false, ['encrypt', 'decrypt'])
|
|
}
|
|
module.exports = importGen;
|
|
|