use native node crypto for sha256

This commit is contained in:
azivner 2017-11-15 18:23:19 -05:00
parent dd5a142fdd
commit 2533b8e121
2 changed files with 11 additions and 14 deletions

View File

@ -2,7 +2,7 @@
const utils = require('./utils'); const utils = require('./utils');
const aesjs = require('./aes'); const aesjs = require('./aes');
const sha256 = require('./sha256'); const crypto = require('crypto');
function getProtectedSessionId(req) { function getProtectedSessionId(req) {
return req.headers['x-protected-session-id']; return req.headers['x-protected-session-id'];
@ -12,15 +12,6 @@ function getDataAes(dataKey) {
return new aesjs.ModeOfOperation.ctr(dataKey, new aesjs.Counter(5)); return new aesjs.ModeOfOperation.ctr(dataKey, new aesjs.Counter(5));
} }
function arraysIdentical(a, b) {
let i = a.length;
if (i !== b.length) return false;
while (i--) {
if (a[i] !== b[i]) return false;
}
return true;
}
function decrypt(dataKey, encryptedBase64) { function decrypt(dataKey, encryptedBase64) {
if (!dataKey) { if (!dataKey) {
return "[protected]"; return "[protected]";
@ -64,9 +55,16 @@ function encrypt(dataKey, plainText) {
} }
function sha256Array(content) { function sha256Array(content) {
const hash = sha256.create(); return crypto.createHash('sha256').update(content).digest();
hash.update(content); }
return hash.array();
function arraysIdentical(a, b) {
let i = a.length;
if (i !== b.length) return false;
while (i--) {
if (a[i] !== b[i]) return false;
}
return true;
} }
module.exports = { module.exports = {

File diff suppressed because one or more lines are too long