Skip to content
org.jasypt.util.text.BasicTextEncryptor for Node.js
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
test
.editorconfig
.eslintrc
.gitignore
.npmignore
.travis.yml
CHANGELOG.md
LICENSE
README.md
encryptor.js
index.js
jasypt.js
package.json
util.js

README.md

Jasypt

NPM version build status Test coverage npm download

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>        秘钥
  -e, --encrypt <msg>         需要加密的文本
  -d, --decrypt <encryptMsg>  需要解密的文本
  -h, --help                  output usage information

$ jasypt -p G0CvDz7oJn60 -e admin

5mLtVOnrEFqnrFuvpJbnpg==

$ jasypt -p G0CvDz7oJn60 -d 5mLtVOnrEFqnrFuvpJbnpg==

admin

解密加密项 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'
    }],
  }
};
You can’t perform that action at this time.