Giter VIP home page Giter VIP logo

jasypt's Introduction

Jasypt

NPM version Codacy build status Test coverage npm downloads/month npm downloads

org.jasypt.util.text.BasicTextEncryptor for Node.js

背景

Spring Boot 集成 jasypt 对配置项进行加密,为了与 Java 体系保持一致,于是有了 Jasypt.js

使用

SDK

'use strict';

const Jasypt = require('jasypt');
const jasypt = new Jasypt();
// 设置秘钥
jasypt.setPassword('G0CvDz7oJn60');
// 加密
const encryptMsg = jasypt.encrypt('admin');
// 解密
const decryptMsg = jasypt.decrypt(encryptMsg);

命令行

$ jasypt -h

Usage: jasypt [options]

Options:
  -v, --version               output the version number
  -p, --password <pwd>        The secret key
  -e, --encrypt <msg>         Text to be encrypting
  -d, --decrypt <encryptMsg>  Text to be decrypting
  -h, --help                  output usage information

Examples:

  $ jasypt -p 0x1995 -e admin
  $ jasypt -p 0x1995 -d nsbC5r0ymz740/aURtuRWw==

解密加密项 for Spring Boot

// 对配置项的ENC(xxx)进行解密
const data = {
  code: 42,
  test: {
    db: 'ENC(c0KA89TBZ6TbLn7E6RIiFQ==)',
    pwd: {
      a: 'ENC(c0KA89TBZ6TbLn7E6RIiFQ==)'
    },
    asad: {
      pwd: {
        str: 'str',
        host: 'ENC(c0KA89TBZ6TbLn7E6RIiFQ==)',
        pwd: 'ENC(c0KA89TBZ6TbLn7E6RIiFQ==)'
      }
    },
    items: [{
      user: 'user1',
      pwd: 'ENC(c0KA89TBZ6TbLn7E6RIiFQ==)'
    }, {
      user: 'user2',
      pwd: 'ENC(c0KA89TBZ6TbLn7E6RIiFQ==)'
    }, {
      user: 'user3',
      pwd: 'ENC(c0KA89TBZ6TbLn7E6RIiFQ==)'
    }],
  }
};

const jasypt = new Jasypt();
jasypt.setPassword('P8dEw34TgvbY');
jasypt.decryptConfig(data);
// 解密出来的内容
const data = {
  code: 42,
  test: {
    db: 'admin',
    pwd: {
      a: 'admin'
    },
    asad: {
      pwd: {
        str: 'str',
        host: 'admin',
        pwd: 'admin'
      }
    },
    items: [{
      user: 'user1',
      pwd: 'admin'
    }, {
      user: 'user2',
      pwd: 'admin'
    }, {
      user: 'user3',
      pwd: 'admin'
    }],
  }
};

jasypt's People

Contributors

rickyes avatar sushanth-kille avatar tripu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jasypt's Issues

Some special characters don't decode correctly

E.g.:

npx jasypt -p 0x1995 -e '£££ abc £££'
rWP4xiNd8l5E9KNjAO2R78NGVXeOzbJHg3OtWrhvElQ=

npx jasypt -p 0x1995 -d rWP4xiNd8l5E9KNjAO2R78NGVXeOzbJHg3OtWrhvElQ=
£££ abc ££��

Stopped working on Node v18

Tried using it with node 18, and got the following error:

$ npx jasypt -p 0x1995 -e admin
node:internal/crypto/cipher:116
    this[kHandle].initiv(cipher, credential, iv, authTagLength);
                  ^

Error: error:0308010C:digital envelope routines::unsupported
    at Cipheriv.createCipherBase (node:internal/crypto/cipher:116:19)
    at Cipheriv.createCipherWithIV (node:internal/crypto/cipher:135:3)
    at new Cipheriv (node:internal/crypto/cipher:243:3)
    at Object.createCipheriv (node:crypto:141:10)
    at Encryptor.encrypt (/home/code/node_modules/jasypt/encryptor.js:58:27)
    at Jasypt.encrypt (/home/code/node_modules/jasypt/jasypt.js:40:28)
    at encrypt (/home/code/node_modules/jasypt/bin/jasypt.js:16:22)
    at Command.<anonymous> (/home/code/node_modules/jasypt/node_modules/commander/index.js:412:13)
    at Command.emit (node:events:513:28)
    at Command.parseOptions (/home/code/node_modules/jasypt/node_modules/commander/index.js:730:14) {
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v18.13.0

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.