Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

browserify-aes

Package Overview
Dependencies
Maintainers
4
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browserify-aes - npm Package Compare versions

Comparing version 0.8.1 to 1.0.0

browser.js

69

decrypter.js

@@ -102,40 +102,37 @@ var aes = require('./aes');

module.exports = function (crypto) {
function createDecipheriv(suite, password, iv) {
var config = modes[suite.toLowerCase()];
if (!config) {
throw new TypeError('invalid suite type');
}
if (typeof iv === 'string') {
iv = new Buffer(iv);
}
if (typeof password === 'string') {
password = new Buffer(password);
}
if (password.length !== config.key/8) {
throw new TypeError('invalid key length ' + password.length);
}
if (iv.length !== config.iv) {
throw new TypeError('invalid iv length ' + iv.length);
}
if (config.type === 'stream') {
return new StreamCipher(modelist[config.mode], password, iv, true);
} else if (config.type === 'auth') {
return new AuthCipher(modelist[config.mode], password, iv, true);
}
return new Decipher(modelist[config.mode], password, iv);
function createDecipheriv(suite, password, iv) {
var config = modes[suite.toLowerCase()];
if (!config) {
throw new TypeError('invalid suite type');
}
if (typeof iv === 'string') {
iv = new Buffer(iv);
}
if (typeof password === 'string') {
password = new Buffer(password);
}
if (password.length !== config.key/8) {
throw new TypeError('invalid key length ' + password.length);
}
if (iv.length !== config.iv) {
throw new TypeError('invalid iv length ' + iv.length);
}
if (config.type === 'stream') {
return new StreamCipher(modelist[config.mode], password, iv, true);
} else if (config.type === 'auth') {
return new AuthCipher(modelist[config.mode], password, iv, true);
}
return new Decipher(modelist[config.mode], password, iv);
}
function createDecipher (suite, password) {
var config = modes[suite.toLowerCase()];
if (!config) {
throw new TypeError('invalid suite type');
}
var keys = ebtk(crypto, password, config.key, config.iv);
return createDecipheriv(suite, keys.key, keys.iv);
function createDecipher (suite, password) {
var config = modes[suite.toLowerCase()];
if (!config) {
throw new TypeError('invalid suite type');
}
return {
createDecipher: createDecipher,
createDecipheriv: createDecipheriv
};
};
var keys = ebtk(password, config.key, config.iv);
return createDecipheriv(suite, keys.key, keys.iv);
}
exports.createDecipher = createDecipher;
exports.createDecipheriv = createDecipheriv;

@@ -86,39 +86,37 @@ var aes = require('./aes');

};
module.exports = function (crypto) {
function createCipheriv(suite, password, iv) {
var config = modes[suite.toLowerCase()];
if (!config) {
throw new TypeError('invalid suite type');
}
if (typeof iv === 'string') {
iv = new Buffer(iv);
}
if (typeof password === 'string') {
password = new Buffer(password);
}
if (password.length !== config.key/8) {
throw new TypeError('invalid key length ' + password.length);
}
if (iv.length !== config.iv) {
throw new TypeError('invalid iv length ' + iv.length);
}
if (config.type === 'stream') {
return new StreamCipher(modelist[config.mode], password, iv);
} else if (config.type === 'auth') {
return new AuthCipher(modelist[config.mode], password, iv);
}
return new Cipher(modelist[config.mode], password, iv);
function createCipheriv(suite, password, iv) {
var config = modes[suite.toLowerCase()];
if (!config) {
throw new TypeError('invalid suite type');
}
function createCipher (suite, password) {
var config = modes[suite.toLowerCase()];
if (!config) {
throw new TypeError('invalid suite type');
}
var keys = ebtk(crypto, password, config.key, config.iv);
return createCipheriv(suite, keys.key, keys.iv);
if (typeof iv === 'string') {
iv = new Buffer(iv);
}
return {
createCipher: createCipher,
createCipheriv: createCipheriv
};
};
if (typeof password === 'string') {
password = new Buffer(password);
}
if (password.length !== config.key/8) {
throw new TypeError('invalid key length ' + password.length);
}
if (iv.length !== config.iv) {
throw new TypeError('invalid iv length ' + iv.length);
}
if (config.type === 'stream') {
return new StreamCipher(modelist[config.mode], password, iv);
} else if (config.type === 'auth') {
return new AuthCipher(modelist[config.mode], password, iv);
}
return new Cipher(modelist[config.mode], password, iv);
}
function createCipher (suite, password) {
var config = modes[suite.toLowerCase()];
if (!config) {
throw new TypeError('invalid suite type');
}
var keys = ebtk(password, config.key, config.iv);
return createCipheriv(suite, keys.key, keys.iv);
}
exports.createCipheriv = createCipheriv;
exports.createCipher = createCipher;

@@ -1,3 +0,7 @@

module.exports = function (crypto, password, keyLen, ivLen) {
var md5 = require('create-hash/md5');
module.exports = EVP_BytesToKey;
function EVP_BytesToKey(password, keyLen, ivLen) {
if (!Buffer.isBuffer(password)) {
password = new Buffer(password, 'binary');
}
keyLen = keyLen/8;

@@ -10,11 +14,12 @@ ivLen = ivLen || 0;

var addmd = 0;
var md, md_buf;
var md_buf;
var i;
var bufs = [];
while (true) {
md = crypto.createHash('md5');
if(addmd++ > 0) {
md.update(md_buf);
bufs.push(md_buf);
}
md.update(password);
md_buf = md.digest();
bufs.push(password);
md_buf = md5(Buffer.concat(bufs));
bufs = [];
i = 0;

@@ -58,2 +63,2 @@ if(keyLen > 0) {

};
};
}
var crypto = require('crypto');
exports.__browserify = require('./inject')
exports.__browserify(crypto, module.exports);
exports.createCipher = exports.Cipher = crypto.createCipher;
exports.createCipheriv = exports.Cipheriv = crypto.createCipheriv;
exports.createDecipher = exports.Decipher = crypto.createDecipher;
exports.createDecipheriv = exports.Decipheriv = crypto.createDecipheriv;
exports.listCiphers = exports.getCiphers = crypto.getCiphers;
{
"name": "browserify-aes",
"version": "0.8.1",
"version": "1.0.0",
"description": "aes, for browserify",
"browser": "browser.js",
"main": "index.js",

@@ -14,3 +15,3 @@ "directories": {

"type": "git",
"url": "git://github.com/calvinmetcalf/browserify-aes.git"
"url": "git://github.com/crypto-browserify/browserify-aes.git"
},

@@ -25,6 +26,7 @@ "keywords": [

"bugs": {
"url": "https://github.com/calvinmetcalf/browserify-aes/issues"
"url": "https://github.com/crypto-browserify/browserify-aes/issues"
},
"homepage": "https://github.com/calvinmetcalf/browserify-aes",
"homepage": "https://github.com/crypto-browserify/browserify-aes",
"dependencies": {
"create-hash": "^1.1.0",
"inherits": "^2.0.1"

@@ -31,0 +33,0 @@ },

browserify-aes
====
[![Build Status](https://travis-ci.org/calvinmetcalf/browserify-aes.svg)](https://travis-ci.org/calvinmetcalf/browserify-aes)
[![Build Status](https://travis-ci.org/crypto-browserify/browserify-aes.svg)](https://travis-ci.org/crypto-browserify/browserify-aes)
Node style aes for use in the browser. Implements:
- createCipher
- createCipheriv
- createDecipher
- createDecipheriv
- getCiphers
In node.js, the `crypto` implementation is used, in browsers it falls back to a pure JavaScript implementation.
Much of this library has been taken from the aes implementation in [triplesec](https://github.com/keybase/triplesec), a partial derivation of [crypto-js](https://code.google.com/p/crypto-js/).
`EVP_BytesToKey` is a straight up port of the same function from OpenSSL as there is literally no documenation on it beyond it using 'undocumented extensions' for longer keys.
var test = require('tape');
var fixtures = require('./fixtures.json');
var _crypto = require('crypto');
var crypto = require('../');
var crypto = require('../browser.js');
var modes = require('../modes');

@@ -110,4 +110,4 @@ var types = Object.keys(modes);

}
var suite = crypto.createCipheriv(cipher, ebtk(_crypto, fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var suite2 = _crypto.createCipheriv(cipher, ebtk(_crypto, fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var suite = crypto.createCipheriv(cipher, ebtk(fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var suite2 = _crypto.createCipheriv(cipher, ebtk(fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var buf = new Buffer('');

@@ -151,4 +151,4 @@ var buf2 = new Buffer('');

}
var suite = crypto.createCipheriv(cipher, ebtk(_crypto, fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var suite2 = _crypto.createCipheriv(cipher, ebtk(_crypto, fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var suite = crypto.createCipheriv(cipher, ebtk(fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var suite2 = _crypto.createCipheriv(cipher, ebtk(fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var buf = new Buffer('');

@@ -179,5 +179,5 @@ var buf2 = new Buffer('');

t.plan(2);
var suite = crypto.createDecipheriv(cipher, ebtk(_crypto, fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var suite = crypto.createDecipheriv(cipher, ebtk(fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var buf = new Buffer('');
var suite2 = _crypto.createDecipheriv(cipher, ebtk(_crypto, fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var suite2 = _crypto.createDecipheriv(cipher, ebtk(fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var buf2 = new Buffer('');

@@ -214,5 +214,5 @@ suite.on('data', function (d) {

t.plan(4);
var suite = crypto.createDecipheriv(cipher, ebtk(_crypto, fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var suite = crypto.createDecipheriv(cipher, ebtk(fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var buf = new Buffer('');
var suite2 = _crypto.createDecipheriv(cipher, ebtk(_crypto, fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var suite2 = _crypto.createDecipheriv(cipher, ebtk(fixture.password, modes[cipher].key).key, isGCM(cipher) ? (new Buffer(fixture.iv, 'hex').slice(0, 12)) : (new Buffer(fixture.iv, 'hex')));
var buf2 = new Buffer('');

@@ -219,0 +219,0 @@ var inbuf = new Buffer(fixture.results.cipherivs[cipher], 'hex');

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc