Skip to content
This repository has been archived by the owner on Jul 10, 2022. It is now read-only.

Commit

Permalink
Initial seed
Browse files Browse the repository at this point in the history
  • Loading branch information
nbarikipoulos committed Mar 11, 2019
0 parents commit b680a26
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/

.DS_Store
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

Copyright (c) 2019 N. Barikipoulos <nikolaos.barikipoulos@outlook.fr>

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.

48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# gulp-cipher-json
[![NPM version][npm-image]][npm-url]

| Package | gulp-cipher-value |
| ------- | ----------------- |
| Description | Gulp wrapper for [json-cipher-value](https://github.com/nbarikipoulos/json-cipher-value). (Un)cipher values of json files retaining their types. |

## Install

```shell
npm install gulp-cipher-json --save-dev
```

## Usage

```js

const gulp = require('gulp');
const cipherJSON = require('gulp-cipher-json');

gulp.task('default', () => gulp.src('src/data/*.json')
.pipe(cipherJSON(
'decrypt',
'my secret password from anywhere'
))
.pipe(gulp.dest('dist/data'))
);
```

## cipherJSON(action, secret, [options])

__action__: either 'encrypt' or 'decrypt'

__secret__: password

__options__: [json-cipher-value](https://github.com/nbarikipoulos/json-cipher-value) options. Note the default settings perform an aes-256-ctr ciphering.


## Credits

- Nikolaos Barikipoulos ([nbarikipoulos](https://github.com/nbarikipoulos))

## License

This module is MIT licensed. See [LICENSE](./LICENSE.md).

[npm-url]: https://www.npmjs.com/package/gulp-cipher-json
[npm-image]: https://img.shields.io/npm/v/gulp-cipher-json.svg
71 changes: 71 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*!
* (The MIT License)
*
* Copyright (c) 2019 N. Barikipoulos <nikolaos.barikipoulos@outlook.fr>
*
* 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.
*/
'use strict'

const through = require('through2');
const PluginError = require('plugin-error');

const createCryptObject = require('json-cipher-value');

const PLUGIN_NAME = 'gulp-cipher-json';

module.exports = (action, secret, options) => {
return through.obj( (file, enc, cb) => {

if (file.isNull()) {
// Do nothing
return cb(null, file);
}

if (file.isStream()) {
cb(new PluginError(
PLUGIN_NAME,
'Streams not supported!'
));
}

// Validation of args

if ( action !== 'encrypt' && action !=='decrypt' ) {
cb(new PluginError(
PLUGIN_NAME,
'action option must be set either to \'crypt\' or \'encrypt\''
));
}
if ( undefined === secret ) {
cb(new PluginError(
PLUGIN_NAME,
'A secret phrase is required'
));
}

//
// Main job
//

if (file.isBuffer()) { // Other cas possible?

let cryptObject = createCryptObject(secret, options);

let encryptedObject = cryptObject[`${action}`].call(
cryptObject,
JSON.parse(file.contents.toString())
);

file.contents = Buffer.from(JSON.stringify(
encryptedObject,
null,
2
));

return cb(null, file);
}
});
};
33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "gulp-cipher-json",
"version": "1.0.0",
"description": "(Un)cipher json values",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"homepage": "https://github.com/nbarikipoulos/gulp-cipher-json#readme",
"author": "Nikolaos Barikipoulos <nikolaos.barikipoulos@outlook.fr>",
"license": "MIT",
"keywords": [
"gulpplugin",
"json",
"crypto",
"cipher",
"encrypt",
"decrypt",
"aes256"
],
"dependencies": {
"json-cipher-value": "^1.1.0",
"plugin-error": "^1.0.1",
"through2": "^3.0.1"
},
"repository": {
"type": "git",
"url": "https://github.com/nbarikipoulos/gulp-cipher-json.git"
},
"engines": {
"node": ">=8.0.0"
}
}

0 comments on commit b680a26

Please sign in to comment.