1 | #! /usr/bin/env node
|
2 | "use strict";
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
19 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
20 | return new (P || (P = Promise))(function (resolve, reject) {
|
21 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
22 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
23 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
24 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
25 | });
|
26 | };
|
27 | Object.defineProperty(exports, "__esModule", { value: true });
|
28 |
|
29 | const crypto_1 = require("../lib/support/crypto");
|
30 |
|
31 | function main() {
|
32 | return __awaiter(this, void 0, void 0, function* () {
|
33 | if (process.argv.length !== 5) {
|
34 | console.error(`Usage: secret encrypt|decrypt KEY TEXT`);
|
35 | process.exit(2);
|
36 | }
|
37 | const action = process.argv[2];
|
38 | const key = process.argv[3];
|
39 | const text = process.argv[4];
|
40 | if (action === "encrypt") {
|
41 | console.log(yield crypto_1.encrypt(text, key));
|
42 | }
|
43 | else if (action === "decrypt") {
|
44 | console.log(yield crypto_1.decrypt(text, key));
|
45 | }
|
46 | else {
|
47 | console.error(`Unsupported action, must be "encrypt" or "decrypt": ${action}`);
|
48 | process.exit(1);
|
49 | }
|
50 | });
|
51 | }
|
52 | main().then(() => process.exit(0), err => {
|
53 | console.error(`Unhandled exception: ${err.message}`);
|
54 | process.exit(99);
|
55 | });
|
56 |
|
\ | No newline at end of file |