Kaynağa Gözat

use the browserified version of crypto packages

pull/342/head
Guillaume Vincent 8 yıl önce
ebeveyn
işleme
260dbd3615
3 değiştirilmiş dosya ile 14 ekleme ve 12 silme
  1. +5
    -4
      index.js
  2. +5
    -8
      lib/index.js
  3. +4
    -0
      package.json

+ 5
- 4
index.js Dosyayı Görüntüle

@@ -1,4 +1,5 @@
import crypto from 'crypto';
var pbkdf2 = require('pbkdf2');
var createHmac = require('create-hmac');

module.exports = {
encryptLogin: _encryptLogin,
@@ -18,7 +19,7 @@ function _encryptLogin(login, masterPassword, {iterations = 8192, keylen = 32}={
if (!login || !masterPassword) {
reject('login and master password parameters could not be empty');
}
crypto.pbkdf2(masterPassword, login, iterations, keylen, 'sha256', (error, key) => {
pbkdf2.pbkdf2(masterPassword, login, iterations, keylen, 'sha256', (error, key) => {
if (error) {
reject('error in pbkdf2');
} else {
@@ -37,7 +38,7 @@ function _renderPassword(encryptedLogin, site, passwordOptions) {

function _createHmac(encryptedLogin, salt) {
return new Promise(resolve => {
resolve(crypto.createHmac('sha256', encryptedLogin).update(salt).digest('hex'));
resolve(createHmac('sha256', new Buffer(encryptedLogin)).update(salt).digest('hex'));
});
}

@@ -104,6 +105,6 @@ function _getPasswordChar(charType, index) {

function createFingerprint(str) {
return new Promise(resolve => {
resolve(crypto.createHmac('sha256', str).digest('hex'))
resolve(createHmac('sha256', new Buffer(str)).digest('hex'))
});
}

+ 5
- 8
lib/index.js Dosyayı Görüntüle

@@ -1,10 +1,7 @@
'use strict';

var _crypto = require('crypto');

var _crypto2 = _interopRequireDefault(_crypto);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var pbkdf2 = require('pbkdf2');
var createHmac = require('create-hmac');

module.exports = {
encryptLogin: _encryptLogin,
@@ -31,7 +28,7 @@ function _encryptLogin(login, masterPassword) {
if (!login || !masterPassword) {
reject('login and master password parameters could not be empty');
}
_crypto2.default.pbkdf2(masterPassword, login, iterations, keylen, 'sha256', function (error, key) {
pbkdf2.pbkdf2(masterPassword, login, iterations, keylen, 'sha256', function (error, key) {
if (error) {
reject('error in pbkdf2');
} else {
@@ -50,7 +47,7 @@ function _renderPassword(encryptedLogin, site, passwordOptions) {

function _createHmac(encryptedLogin, salt) {
return new Promise(function (resolve) {
resolve(_crypto2.default.createHmac('sha256', encryptedLogin).update(salt).digest('hex'));
resolve(createHmac('sha256', new Buffer(encryptedLogin)).update(salt).digest('hex'));
});
}

@@ -119,6 +116,6 @@ function _getPasswordChar(charType, index) {

function createFingerprint(str) {
return new Promise(function (resolve) {
resolve(_crypto2.default.createHmac('sha256', str).digest('hex'));
resolve(createHmac('sha256', new Buffer(str)).digest('hex'));
});
}

+ 4
- 0
package.json Dosyayı Görüntüle

@@ -27,6 +27,10 @@
"es2015"
]
},
"dependencies": {
"create-hmac": "^1.1.4",
"pbkdf2": "^3.0.9"
},
"devDependencies": {
"babel-cli": "^6.16.0",
"babel-core": "^6.17.0",


Yükleniyor…
İptal
Kaydet