Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

aes working #1

Merged
merged 1 commit into from
Mar 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"homepage": "https://github.com/Storj/storj-crypto",
"dependencies": {
"browserify-aes": "^1.0.6",
"readable-stream": "^2.2.3"
}
}
4 changes: 1 addition & 3 deletions src/crypto/createDecipheriv-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ function DecryptStream(enc, key, iv) {
self.algorithm.length = 128
});

//this.iv = iv;

stream.Transform.call(this);
}

Expand All @@ -45,7 +43,6 @@ util.inherits(DecryptStream, stream.Transform);
DecryptStream.prototype._transform = function(chunk, enc, callback) {
console.log('chunk piped to from concat s')
console.log(chunk)
//console.log(this.iv.length)
var self = this;
// window.crypto.subtle.decrypt(
// {
Expand Down Expand Up @@ -107,6 +104,7 @@ DecryptStream.prototype._flush = function(callback) {

module.exports = function(enc, key, iv) {
// do webcrypto here
var decipher = ciphers.createDecipheriv(mode, key, iv)
var ds = new DecryptStream(enc, key, iv)
return ds
}
Expand Down
28 changes: 16 additions & 12 deletions src/crypto/createDecipheriv.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
'use strict'

let webcrypto
try {
webcrypto = window.crypto
} catch (err) {
// not available, use the code below
}
var crypto = require('browserify-aes')

if (webcrypto){
module.exports = require('./createDecipheriv-browser')
} else {
// do node crypto here
var crypto = require('crypto')
// NOTE: There is no streaming mode in AES-CTR for webcrypto
// Streaming mode is used by the node implementation so
// we resort to requiring AES in pure ja for now

// let webcrypto
// try {
// webcrypto = window.crypto
// } catch (err) {
// // not available, use the code below
// }

//if (webcrypto){
// module.exports = require('./createDecipheriv-browser')
//} else {
module.exports = function(enc, key, iv) {
return crypto.createDecipheriv(enc, key, iv)
}
}
//}