2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.sparky.util;
25 import org.apache.commons.cli.BasicParser;
26 import org.apache.commons.cli.CommandLine;
27 import org.apache.commons.cli.CommandLineParser;
28 import org.apache.commons.cli.Options;
29 import org.apache.commons.cli.ParseException;
30 import org.eclipse.jetty.util.security.Password;
33 * The Class Encryptor.
35 public class Encryptor {
38 * Instantiates a new encryptor.
46 * @param value the value
49 public String decryptValue(String value) {
50 String decyptedValue = "";
53 decyptedValue = Password.deobfuscate(value);
54 } catch (Exception exc) {
55 System.err.println("Cannot decrypt '" + value + "': " + exc.toString());
64 public static void usage() {
73 public static void usage(String msg) {
75 System.err.println(msg);
77 System.err.println("Usage: java Encryptor -e value");
78 System.err.println("\tEncrypt the given value");
79 System.err.println("Usage: java Encryptor -d value");
80 System.err.println("\tDecrypt the given value");
87 * @param args the arguments
89 public static void main(String[] args) {
91 Options options = new Options();
92 options.addOption("d", true, "value to decrypt");
93 options.addOption("h", false, "show help");
94 options.addOption("?", false, "show help");
97 boolean encrypt = false;
98 boolean decrypt = false;
100 CommandLineParser parser = new BasicParser();
101 CommandLine cmd = null;
104 cmd = parser.parse(options, args);
106 if (cmd.hasOption("d")) {
107 value = cmd.getOptionValue("d");
111 if (cmd.hasOption("?") || cmd.hasOption("h")) {
116 if ((encrypt && decrypt) || (!encrypt && !decrypt)) {
117 usage("Must specify one (and only one) of the -e or -d options");
120 Encryptor encryptor = new Encryptor();
123 String out = encryptor.decryptValue(value);
124 System.out.println(out);
126 } catch (ParseException exc) {
127 System.out.println("Failed to parse command line properties: " + exc.toString());
128 } catch (Exception exc) {
129 System.out.println("Failure: " + exc.toString());