2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 package org.openecomp.sparky.util;
28 import org.apache.commons.cli.BasicParser;
29 import org.apache.commons.cli.CommandLine;
30 import org.apache.commons.cli.CommandLineParser;
31 import org.apache.commons.cli.Options;
32 import org.apache.commons.cli.ParseException;
33 import org.eclipse.jetty.util.security.Password;
36 * The Class Encryptor.
38 public class Encryptor {
41 * Instantiates a new encryptor.
49 * @param value the value
52 public String decryptValue(String value) {
53 String decyptedValue = "";
56 decyptedValue = Password.deobfuscate(value);
57 } catch (Exception exc) {
58 System.err.println("Cannot decrypt '" + value + "': " + exc.toString());
67 public static void usage() {
76 public static void usage(String msg) {
78 System.err.println(msg);
80 System.err.println("Usage: java Encryptor -e value");
81 System.err.println("\tEncrypt the given value");
82 System.err.println("Usage: java Encryptor -d value");
83 System.err.println("\tDecrypt the given value");
90 * @param args the arguments
92 public static void main(String[] args) {
94 Options options = new Options();
95 options.addOption("d", true, "value to decrypt");
96 options.addOption("h", false, "show help");
97 options.addOption("?", false, "show help");
100 boolean encrypt = false;
101 boolean decrypt = false;
103 CommandLineParser parser = new BasicParser();
104 CommandLine cmd = null;
107 cmd = parser.parse(options, args);
109 if (cmd.hasOption("d")) {
110 value = cmd.getOptionValue("d");
114 if (cmd.hasOption("?") || cmd.hasOption("h")) {
119 if ((encrypt && decrypt) || (!encrypt && !decrypt)) {
120 usage("Must specify one (and only one) of the -e or -d options");
123 Encryptor encryptor = new Encryptor();
126 String out = encryptor.decryptValue(value);
127 System.out.println(out);
129 } catch (ParseException exc) {
130 System.out.println("Failed to parse command line properties: " + exc.toString());
131 } catch (Exception exc) {
132 System.out.println("Failure: " + exc.toString());