https://github.com/lukeed/salteen
A snappy and lightweight (259B) utility to encrypt and decrypt values with salt.
https://github.com/lukeed/salteen
Last synced: 10 months ago
JSON representation
A snappy and lightweight (259B) utility to encrypt and decrypt values with salt.
- Host: GitHub
- URL: https://github.com/lukeed/salteen
- Owner: lukeed
- License: mit
- Created: 2019-03-24T23:26:12.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-30T18:36:43.000Z (over 7 years ago)
- Last Synced: 2024-11-14T16:44:39.250Z (over 1 year ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 95
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
- awesome-list - salteen
README
# salteen [](https://travis-ci.org/lukeed/salteen)
> A snappy and lightweight (259B) utility to encrypt and decrypt values with salt.
Both `encrypt` and `decrypt` are factory functions that accept a `salt` key and return new functions to be called with the unique value(s) to handle. This allows you reuse instances across multiple values.
This module is available in three formats:
* **CommonJS**: `dist/salteen.js`
* **ESModule**: `dist/salteen.mjs`
* **UMD**: `dist/salteen.min.js`
## Install
```
$ npm install --save salteen
```
## Usage
```js
const { encrypt, decrypt } = require('salteen');
const MY_SALT = 'foobar'; // PS: the longer the better
const encoder = encrypt(MY_SALT);
const decoder = decrypt(MY_SALT);
['hello', 'world'].map(encoder);
//=> ['7f727b7b78', '6078657b73']
['7f727b7b78', '6078657b73'].map(decoder);
//=> ['hello', 'world']
```
## API
### encrypt(salt)
Returns: `Function`
Returns a new `Function` which will accept a `value` to be encrypted, using `salt` as the salting value.
#### salt
Type: `String`
The salting value to be used – longer salts are more secure.
### decrypt(salt)
return `Function`
Returns a new `Function` which will accept a `value` to be decrypted, using `salt` as the salting value.
#### salt
Type: `String`
The salting value to be used – longer salts are more secure.
## Benchmarks
> Results below are with Node v11.11.0
```
encrypt x 281,299 ops/sec ±0.66% (97 runs sampled)
decrypt x 383,827 ops/sec ±1.81% (90 runs sampled)
```
## License
MIT © [Luke Edwards](https://lukeed.com)