Giter VIP home page Giter VIP logo

Comments (1)

tsmx avatar tsmx commented on July 22, 2024

Hi!

Encrypting the entire file (meaning ALL of its contents, keys & values) is not the original intention of my package @tsmx/secure-config and this supporting tool as it has some major drawbacks:

  • the result would not be a valid JSON anymore
  • the result would be completely unreadable for humans, which makes the handling extremely difficult

Since the additional gain of security is very small I defintively do not recommend to encrypt the entire file.

But: Nevertheless you can achieve your goal very easy with the provided library @tsmx/string-crypto which I also use in this project.

Encrypt an entire JSON file

const sc = require('@tsmx/string-crypto');
const fs = require('fs');
const jsonFile = require('test.json');
let encryptedJson = sc.encrypt(JSON.stringify(jsonFile));
fs.writeFileSync('test.json.enc', encryptedJson);

Decrypt the JSON back

const sc = require('@tsmx/string-crypto');
const fs = require('fs');
let decryptedJsonFile = JSON.parse(sc.decrypt(fs.readFileSync('test.json.enc').toString()));

Note: @tsmx/string-crypto by default uses the environment variable ENCRYPTION_KEY. If you need to use an environment variable with another name, simply pass the key directly...

sc.encrypt(text, { key: process.env['YOUR_VAR_NAME'] });
sc.decrypt(text, { key: process.env['YOUR_VAR_NAME'] });

Hope that helps!

Kind regards

P.S.: closing the issue as it's not relevant for this project

from secure-config-tool.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.