Create a Compatibility namespace
This commit is contained in:
parent
202a047edc
commit
1b0f6836dc
14 changed files with 257 additions and 275 deletions
|
|
@ -8,32 +8,39 @@ var _ = require('lodash');
|
|||
var defaultSalt = 'mjuBtGybi/4=';
|
||||
var defaultIterations = 100;
|
||||
|
||||
sjcl.defaults = {
|
||||
v: 1,
|
||||
iter: 100,
|
||||
ks: 128,
|
||||
ts: 64,
|
||||
mode: "ccm",
|
||||
adata: "",
|
||||
cipher: "aes"
|
||||
},
|
||||
|
||||
module.exports = {
|
||||
|
||||
kdf: function(value1, value2, salt, iterations) {
|
||||
iterations = iterations || defaultIterations;
|
||||
salt = salt || defaultSalt;
|
||||
/**
|
||||
* @param {string} password
|
||||
* @param {string} salt - base64 encoded, defaults to 'mjuBtGybi/4='
|
||||
* @param {number} iterations - defaults to 100
|
||||
* @param {number} length - bits, defaults to 512 bits
|
||||
* @returns {string} base64 encoded pbkdf2 derivation using sha1 for hmac
|
||||
*/
|
||||
kdf: function(password, salt, iterations, length) {
|
||||
return sjcl.codec.base64.fromBits(
|
||||
this.kdfbinary(password, salt, iterations, length)
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {string} password
|
||||
* @param {string} salt - base64 encoded, defaults to 'mjuBtGybi/4='
|
||||
* @param {number} iterations - defaults to 100
|
||||
* @param {number} length - bits, defaults to 512 bits
|
||||
* @returns {string} base64 encoded pbkdf2 derivation using sha1 for hmac
|
||||
*/
|
||||
kdfbinary: function(password, salt, iterations, length) {
|
||||
iterations = iterations || defaultIterations;
|
||||
length = length || 512;
|
||||
salt = sjcl.codec.base64.toBits(salt || defaultSalt);
|
||||
|
||||
var password = value1 + (value2 || '');
|
||||
var hash = sjcl.hash.sha256.hash(sjcl.hash.sha256.hash(password));
|
||||
var salt = sjcl.codec.base64.toBits(salt);
|
||||
var prff = function(key) {
|
||||
return new sjcl.misc.hmac(hash, sjcl.hash.sha1);
|
||||
};
|
||||
|
||||
var bits = sjcl.misc.pbkdf2(hash, salt, iterations, 64 * 8, prff);
|
||||
var base64 = sjcl.codec.base64.fromBits(bits);
|
||||
return base64;
|
||||
return sjcl.misc.pbkdf2(hash, salt, iterations, length, prff);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue