UNPKG

2.39 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 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};
27Object.defineProperty(exports, "__esModule", { value: true });
28// Simple script to help encrypt and decrypt secret data
29const crypto_1 = require("../lib/support/crypto");
30/* tslint:disable:no-console */
31function 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}
52main().then(() => process.exit(0), err => {
53 console.error(`Unhandled exception: ${err.message}`);
54 process.exit(99);
55});
56//# sourceMappingURL=secret.js.map
\No newline at end of file