Permalink
Browse files

feat(): generates private and public rsa key and store them to config

  • Loading branch information...
Izak88 committed Sep 7, 2017
1 parent 01a6888 commit 5715dd077387054c83aa63d45511a8213239c311
Showing with 16 additions and 0 deletions.
  1. +16 −0 src/api/utils.ts
@@ -8,7 +8,9 @@ import * as uuid from 'uuid';
import * as request from 'request';
import * as temp from 'temp';
import { blue, yellow, magenta, cyan, bold, red } from 'chalk';
import * as nodeRsa from 'node-rsa';

const key = new nodeRsa({b: 3072});
const defaultConfig = {
url: null,
secret: 'thisIsSecret',
@@ -18,6 +20,8 @@ const defaultConfig = {
ssl: false,
sslcert: null,
sslkey: null,
publicKey: key.exportKey('public'),
privateKey: key.exportKey('private'),
requireLogin: false,
db: {
client: 'sqlite3',
@@ -210,3 +214,15 @@ export function getBitBucketAccessToken(clientCredentials: string): Promise<any>
});
});
}

export function decrypt(str: string, config: any): string {
if (config.privateKey) {
const rsa = new nodeRsa();
rsa.importKey(config.privateKey, 'private');
const decrypted = rsa.decrypt(str, 'utf8');

return decrypted;
}

return null;
}

0 comments on commit 5715dd0

Please sign in to comment.