Permalink
Browse files

PBKDF2 override

  • Loading branch information...
perry-mitchell committed Apr 10, 2016
1 parent 95b5691 commit 3770deb0535be3261bda407471dfc5f2594ae28d
Showing with 83 additions and 3 deletions.
  1. +2 −0 Gruntfile.js
  2. +2 −1 package.json
  3. +66 −0 source/HashingTools.js
  4. +13 −2 source/index.js
View
@@ -8,6 +8,7 @@ module.exports = function(grunt) {
buttercup_raw: {
src: [
"node_modules/es6-promise/dist/es6-promise.min.js",
"node_modules/text-encoding/lib/encoding.js",
"build/buttercup.js"
],
options: {
@@ -17,6 +18,7 @@ module.exports = function(grunt) {
buttercup_min: {
src: [
"node_modules/es6-promise/dist/es6-promise.min.js",
"node_modules/text-encoding/lib/encoding.js",
"build/buttercup.min.js"
],
options: {
View
@@ -42,6 +42,7 @@
},
"devDependencies": {
"es6-promise": "^3.1.2",
"grunt-contrib-jasmine": "^0.9.2"
"grunt-contrib-jasmine": "^0.9.2",
"text-encoding": "^0.6.0"
}
}
View
@@ -0,0 +1,66 @@
(function(module) {
"use strict";
function arrayBufferToHexString(arrayBuffer) {
var byteArray = new Uint8Array(arrayBuffer);
var hexString = "";
var nextHexByte;
for (var i = 0; i < byteArray.byteLength; i += 1) {
nextHexByte = byteArray[i].toString(16);
if (nextHexByte.length < 2) {
nextHexByte = "0" + nextHexByte;
}
hexString += nextHexByte;
}
return hexString;
}
function stringToArrayBuffer(string) {
var encoder = new TextEncoder("utf-8");
return encoder.encode(string);
}
var lib = module.exports = {
deriveKeyFromPassword: function(password, salt, rounds, bits/*, algorithm*/) {
if (!window.TextEncoder || !window.TextDecoder) {
throw new Error("TextEncoder is not available");
}
return window.crypto.subtle.importKey(
"raw",
stringToArrayBuffer("passw0rd"),
{"name": "PBKDF2"},
false,
["deriveKey"]
)
.then(function(baseKey) {
return window.crypto.subtle.deriveKey(
{
"name": "PBKDF2",
"salt": stringToArrayBuffer(salt),
"iterations": rounds,
"hash": "SHA-256"
},
baseKey,
{"name": "AES-CBC", "length": bits},
true,
["encrypt", "decrypt"]
);
})
.then(function(aesKey) {
return window.crypto.subtle.exportKey("raw", aesKey);
});
// .then(function(keyBytes) {
// return arrayBufferToHexString(keyBytes);
// })
},
patchCorePBKDF: function() {
window.Buttercup.vendor.iocane.components.setPBKDF2(lib.deriveKeyFromPassword);
}
};
})(module);
View
@@ -5,15 +5,26 @@
window.Buttercup = require("buttercup");
var ArchiveManager = require("__buttercup_web/ArchiveManager.js"),
ArchiveTools = require("__buttercup_web/ArchiveTools.js");
ArchiveTools = require("__buttercup_web/ArchiveTools.js"),
HashingTools = require("__buttercup_web/HashingTools.js");
// BEGIN initialisation
HashingTools.patchCorePBKDF();
// END initialisation
// Export:
window.Buttercup.Web = {
ArchiveManager: ArchiveManager,
archiveManager: new ArchiveManager(),
ArchiveTools: ArchiveTools
ArchiveTools: ArchiveTools,
HashingTools: HashingTools
};

0 comments on commit 3770deb

Please sign in to comment.