UNPKG

2.31 kBJavaScriptView Raw
1#! /usr/bin/env node
2"use strict";
3/*
4 * Copyright © 2019 Atomist, Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
19 return new (P || (P = Promise))(function (resolve, reject) {
20 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
23 step((generator = generator.apply(thisArg, _arguments || [])).next());
24 });
25};
26Object.defineProperty(exports, "__esModule", { value: true });
27// Simple script to help encrypt and decrypt secret data
28const crypto_1 = require("../lib/support/crypto");
29/* tslint:disable:no-console */
30function main() {
31 return __awaiter(this, void 0, void 0, function* () {
32 if (process.argv.length !== 5) {
33 console.error(`Usage: secret encrypt|decrypt KEY TEXT`);
34 process.exit(2);
35 }
36 const action = process.argv[2];
37 const key = process.argv[3];
38 const text = process.argv[4];
39 if (action === "encrypt") {
40 console.log(yield crypto_1.encrypt(text, key));
41 }
42 else if (action === "decrypt") {
43 console.log(yield crypto_1.decrypt(text, key));
44 }
45 else {
46 console.error(`Unsupported action, must be "encrypt" or "decrypt": ${action}`);
47 process.exit(1);
48 }
49 });
50}
51main().then(() => process.exit(0), err => {
52 console.error(`Unhandled exception: ${err.message}`);
53 process.exit(99);
54});
55//# sourceMappingURL=secret.js.map
\No newline at end of file