pax_global_header00006660000000000000000000000064132633747540014530gustar00rootroot0000000000000052 comment=79b8cb5b5c78ff328a4e537cfe8374f1daa5cd8b browserify-cipher-1.0.1/000077500000000000000000000000001326337475400151725ustar00rootroot00000000000000browserify-cipher-1.0.1/.gitignore000066400000000000000000000000151326337475400171560ustar00rootroot00000000000000node_modules browserify-cipher-1.0.1/.travis.yml000066400000000000000000000003101326337475400172750ustar00rootroot00000000000000sudo: false language: node_js node_js: - "4" - "5" - "6" - "7" matrix: include: - node_js: "7" env: TEST_SUITE=standard env: - TEST_SUITE=unit script: npm run-script $TEST_SUITE browserify-cipher-1.0.1/LICENSE000066400000000000000000000021151326337475400161760ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014-2017 Calvin Metcalf & contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. browserify-cipher-1.0.1/README.md000066400000000000000000000004561326337475400164560ustar00rootroot00000000000000browserify-cipher === [![Build Status](https://travis-ci.org/crypto-browserify/browserify-cipher.svg)](https://travis-ci.org/crypto-browserify/browserify-cipher) Provides createCipher, createDecipher, createCipheriv, createDecipheriv and getCiphers for the browserify. Includes AES and DES ciphers. browserify-cipher-1.0.1/browser.js000066400000000000000000000037451326337475400172240ustar00rootroot00000000000000var DES = require('browserify-des') var aes = require('browserify-aes/browser') var aesModes = require('browserify-aes/modes') var desModes = require('browserify-des/modes') var ebtk = require('evp_bytestokey') function createCipher (suite, password) { suite = suite.toLowerCase() var keyLen, ivLen if (aesModes[suite]) { keyLen = aesModes[suite].key ivLen = aesModes[suite].iv } else if (desModes[suite]) { keyLen = desModes[suite].key * 8 ivLen = desModes[suite].iv } else { throw new TypeError('invalid suite type') } var keys = ebtk(password, false, keyLen, ivLen) return createCipheriv(suite, keys.key, keys.iv) } function createDecipher (suite, password) { suite = suite.toLowerCase() var keyLen, ivLen if (aesModes[suite]) { keyLen = aesModes[suite].key ivLen = aesModes[suite].iv } else if (desModes[suite]) { keyLen = desModes[suite].key * 8 ivLen = desModes[suite].iv } else { throw new TypeError('invalid suite type') } var keys = ebtk(password, false, keyLen, ivLen) return createDecipheriv(suite, keys.key, keys.iv) } function createCipheriv (suite, key, iv) { suite = suite.toLowerCase() if (aesModes[suite]) return aes.createCipheriv(suite, key, iv) if (desModes[suite]) return new DES({ key: key, iv: iv, mode: suite }) throw new TypeError('invalid suite type') } function createDecipheriv (suite, key, iv) { suite = suite.toLowerCase() if (aesModes[suite]) return aes.createDecipheriv(suite, key, iv) if (desModes[suite]) return new DES({ key: key, iv: iv, mode: suite, decrypt: true }) throw new TypeError('invalid suite type') } function getCiphers () { return Object.keys(desModes).concat(aes.getCiphers()) } exports.createCipher = exports.Cipher = createCipher exports.createCipheriv = exports.Cipheriv = createCipheriv exports.createDecipher = exports.Decipher = createDecipher exports.createDecipheriv = exports.Decipheriv = createDecipheriv exports.listCiphers = exports.getCiphers = getCiphers browserify-cipher-1.0.1/index.js000066400000000000000000000005451326337475400166430ustar00rootroot00000000000000var crypto = require('crypto') 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 browserify-cipher-1.0.1/package.json000066400000000000000000000011611326337475400174570ustar00rootroot00000000000000{ "name": "browserify-cipher", "version": "1.0.1", "description": "ciphers for the browser", "main": "index.js", "dependencies": { "browserify-aes": "^1.0.4", "browserify-des": "^1.0.0", "evp_bytestokey": "^1.0.0" }, "browser": "browser.js", "devDependencies": { "standard": "^10.0.2", "tap-spec": "^4.1.0", "tape": "^4.2.0" }, "scripts": { "test": "standard && node test.js | tspec" }, "author": "Calvin Metcalf ", "license": "MIT", "repository": { "type": "git", "url": "git@github.com:crypto-browserify/browserify-cipher.git" } } browserify-cipher-1.0.1/test.js000066400000000000000000000034571326337475400165200ustar00rootroot00000000000000var test = require('tape') var crypto = require('crypto') var desModes = require('browserify-des/modes') var aesModes = require('browserify-aes/modes') var ourCrypto = require('./browser') function runIvTest (mode, keyLen, ivLen) { test('mode: ' + mode, function (t) { var i = 0 while (++i < 10) { run(i) } function run (i) { t.test('run: ' + i, function (t) { t.plan(2) var key = crypto.randomBytes(keyLen) var iv = crypto.randomBytes(ivLen) var text = crypto.randomBytes(200) var ourEncrypt try { ourEncrypt = ourCrypto.createCipheriv(mode, key, iv) } catch (e) { t.notOk(e, e.stack) } var nodeEncrypt try { nodeEncrypt = crypto.createCipheriv(mode, key, iv) } catch (e) { t.notOk(e, e.stack) } var ourCipherText = Buffer.concat([ourEncrypt.update(text), ourEncrypt.final()]) var authTag if (mode.slice(-3) === 'gcm') { authTag = ourEncrypt.getAuthTag() } var nodeCipherText = Buffer.concat([nodeEncrypt.update(text), nodeEncrypt.final()]) t.equals(nodeCipherText.toString('hex'), ourCipherText.toString('hex')) var ourDecrypt = ourCrypto.createDecipheriv(mode, key, iv) if (mode.slice(-3) === 'gcm') { ourDecrypt.setAuthTag(authTag) } var plainText = Buffer.concat([ourDecrypt.update(ourCipherText), ourDecrypt.final()]) t.equals(text.toString('hex'), plainText.toString('hex')) }) } }) } Object.keys(aesModes).forEach(function (modeName) { var mode = aesModes[modeName] runIvTest(modeName, mode.key / 8, mode.iv) }) Object.keys(desModes).forEach(function (modeName) { var mode = desModes[modeName] runIvTest(modeName, mode.key, mode.iv) })