Skip to content

Commit

Permalink
Merge ac5c753 into 5829f39
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Maurer committed Oct 11, 2016
2 parents 5829f39 + ac5c753 commit 92a5155
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 147 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: node_js
sudo: false
node_js:
- "6"
- "5"
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Crypto Extra Changelog

## v0.4

- BREAKING: Removed both Bcrypt methods (https://github.com/jsonmaur/node-crypto-extra/issues/1)
- Bug fixes

## v0.3

- Removed [npmjs.org/bcryptjs]() package in favor of [npmjs.org/bcrypt](), which relies on `node-gyp` for faster results.
Expand Down
42 changes: 11 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"sha1",
"md5",
"aes256",
"bcrypt",
"random",
"hex",
"cipher",
Expand All @@ -46,39 +45,20 @@
},
"devDependencies": {
"ava": "0.16.0",
"babel-cli": "6.11.4",
"babel-eslint": "6.1.2",
"babel-plugin-transform-runtime": "6.12.0",
"babel-preset-es2015": "6.13.2",
"babel-preset-stage-2": "6.13.0",
"babel-register": "6.11.6",
"coveralls": "2.11.12",
"npm-run-all": "3.0.0",
"nyc": "8.1.0",
"sinon": "1.17.5",
"snazzy": "4.0.1",
"standard": "7.1.2"
},
"dependencies": {
"babel-runtime": "6.11.6",
"bcrypt": "0.8.7"
},
"standard": {
"parser": "babel-eslint"
"babel-cli": "6.16.0",
"babel-preset-es2015": "6.16.0",
"babel-register": "6.16.3",
"coveralls": "2.11.14",
"npm-run-all": "3.1.0",
"nyc": "8.3.1",
"sinon": "1.17.6",
"snazzy": "5.0.0",
"standard": "8.4.0"
},
"dependencies": {},
"babel": {
"presets": [
"es2015",
"stage-2"
],
"plugins": [
[
"transform-runtime",
{
"polyfill": false,
"regenerator": true
}
]
"es2015"
]
},
"ava": {
Expand Down
52 changes: 11 additions & 41 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ Adds convenience methods to the native Node.js [crypto module](https://nodejs.or

- [Getting Started](#getting-started)
- [API](#api)
- [generateKey](#api-generate)
- [encrypt](#api-encrypt)
- [decrypt](#api-decrypt)
- [generateKey](#api-generate)
- [hash](#api-hash)
- [bcryptHash](#api-bcrypt-hash)
- [bcryptCompare](#api-bcrypt-compare)
- [randomString](#api-random-string)
- [randomNumber](#api-random-number)
- [native crypto methods](https://nodejs.org/api/crypto.html)
Expand Down Expand Up @@ -44,6 +42,16 @@ crypto.hash('hello')
<a name="api"></a>
## API

<a name="api-generate"></a>
### .generateKey (length)

Generates a random 256-bit key that can be used as an encryption key.

- **length** - The length of the key you want to generate. **Must be an even number.**

> Type: `number`
> Default: `32`
<a name="api-encrypt"></a>
### .encrypt (value, secretKey)

Expand Down Expand Up @@ -72,16 +80,6 @@ Decrypts a value using AES-256-CTR.
> Type: `string`
> Default: `process.env.ENCRYPTION_KEY`
<a name="api-generate"></a>
### .generateKey (length)

Generates a random 256-bit key that can be used as an encryption key.

- **length** - The length of the key you want to generate. **Must be an even number.**

> Type: `number`
> Default: `32`
<a name="api-hash"></a>
### .hash (value, options)

Expand All @@ -106,34 +104,6 @@ Hashes a string with the provided algorithm.
> Type: `string`
> Default: `SHA256`
<a name="api-bcrypt-hash"></a>
### .bcryptHash (value, options)

Get the bcrypt hash of a string. Returns a promise resolving with the hash.

- **value** - The value you want to hash with bcrypt.

> Type: `string`
- **options**
- **saltRounds** - The number of rounds to use for generating the salt.

> Type: `integer`
> Default: `10`
<a name="api-bcrypt-compare"></a>
### .bcryptCompare (value, hash)

Compare a value to a bcrypt hash to validate whether they're the same. Returns a promise resolving with a boolean.

- **value** - The value to compare to the hash.

> Type: `string`
- **hash** - The bcrypt hash to use in the comparison.

> Type: `string`
<a name="api-random-string"></a>
### .randomString (length, charset)

Expand Down
42 changes: 0 additions & 42 deletions src/bcrypt.js

This file was deleted.

15 changes: 0 additions & 15 deletions src/bcrypt.test.js

This file was deleted.

24 changes: 11 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import crypto from 'crypto'
import { encrypt, decrypt, generateKey } from './encryption'
import { hash } from './hash'
import { bcryptHash, bcryptCompare } from './bcrypt'
import { randomString, randomNumber } from './random'

module.exports = Object.assign(crypto, {
encrypt, decrypt, generateKey, // from encryption
hash, // from hash
bcryptHash, bcryptCompare, // from bcrypt
randomString, randomNumber // from random
generateKey,
encrypt,
decrypt,
hash,
randomString,
randomNumber,

/* deprecated methods */
// none! :)
bcryptHash: () => deprecationNotice('bcrypt is no longer supported in this module! See https://github.com/jsonmaur/node-crypto-extra/issues/1'),
bcryptCompare: () => deprecationNotice('bcrypt is no longer supported in this module! See https://github.com/jsonmaur/node-crypto-extra/issues/1')
})

// function deprecationNotice (oldName, newName, msg) {
// const first = oldName ? `${oldName}() is now deprecated. ` : ''
// const second = newName ? `use ${newName}() instead.` : ''
//
// if (msg) console.log(`crypto-extra: ${msg}`)
// else console.log(`crypto-extra: ${first}${second}`)
// }
function deprecationNotice (msg) {
console.log(`crypto-extra: ${msg}`)
}
8 changes: 4 additions & 4 deletions src/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export function randomString (size = 10, charset) {
size = typeof size !== 'number' ? size = parseInt(size, 10) : size
if (size <= 0) throw new Error('random size must be above 0!')

if (typeof charset !== 'string') {
throw new TypeError(`charset must be a string, got ${typeof charset}`)
}

const bytes = randomBytes(size)
const chars = charset || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'

if (typeof chars !== 'string') {
throw new TypeError(`charset must be a string, got ${typeof chars}`)
}

let value = ''
for (let i = 0, len = bytes.length; i < len; i++) {
value += chars[bytes.readUInt8(i) % chars.length]
Expand Down
1 change: 0 additions & 1 deletion src/random.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ test('randomString()', (t) => {
t.is(randomString(20).length, 20)
t.throws(() => randomString(0), Error)
t.throws(() => randomString(-5), Error)
t.throws(() => randomString('5'), TypeError)
})

test('randomNumber()', (t) => {
Expand Down

0 comments on commit 92a5155

Please sign in to comment.