Permalink
Browse files

feat(): added encrypt and decrypt functions to cli

  • Loading branch information...
Izak88 committed Sep 7, 2017
1 parent e73ffda commit 01a688848bf71d276a41f80a0fdf37ac5217dc05
Showing with 2,819 additions and 14 deletions.
  1. +27 −2 src/cli/encrypt.ts
  2. +31 −7 src/cli/index.ts
  3. +2,724 −1 src/cli/package-lock.json
  4. +16 −2 src/cli/package.json
  5. +20 −0 src/cli/utils.ts
  6. +1 −2 src/cli/webpack.cli.js
@@ -1,3 +1,28 @@
export function encrypt(variable: string): string {
return 'not implemented!';
import * as nodeRsa from 'node-rsa';
import { getHttpJsonResponse } from './utils';

export function encrypt(str: string, server: string): Promise<any> {
return getHttpJsonResponse(`${server}/api/keys/public`)
.then(response => {
if (response) {
let key = response.key;
let rsa = new nodeRsa();
rsa.importKey(key, 'public');
let encrypted = rsa.encrypt(str, 'base64');

return encrypted;
}

return null;
}).catch(err => Promise.reject(err));
}

export function decrypt(str: string, privateKey: string): Promise<any> {
return new Promise((resolve, reject) => {
let rsa = new nodeRsa();
rsa.importKey(privateKey, 'private');
let decrypted = rsa.decrypt(str, 'utf8');

resolve(decrypted);
});
}
@@ -1,14 +1,38 @@
const minimist = require('minimist');
import * as minimist from 'minimist';
import { red, green, yellow } from 'chalk';
import { encrypt, decrypt } from './encrypt';

const argv = minimist(process.argv.slice(2));

import { encrypt } from './encrypt';
if (argv.encrypt) {
if (argv.server) {
encrypt(argv.encrypt, argv.server)
.then(result => {
if (result) {
console.log(green(result));
} else {
console.log(red('Error: retreiving public key from server failed!'));
}
}).catch(err => console.log(red(err)));
} else {
console.log(red('Server paramter is missing'));
}
}

if (argv.encryptVariable) {
encrypt(argv.encryptVariable);
console.log('not implemented yet');
if (argv.decrypt) {
if (argv.privatekey) {
decrypt(argv.decrypt, argv.privatekey)
.then(result => {
if (result) {
console.log(green(result));
}
}).catch(err => console.log(red(err)));
} else {
console.log(red('Error: private key missing'));
}
}

if (argv.checkConfig) {
console.log(argv.checkConfig);
console.log('not implemented yet');
console.log(yellow(argv.checkConfig));
console.log(yellow('not implemented yet'));
}
Oops, something went wrong.

0 comments on commit 01a6888

Please sign in to comment.