c24f2c24f1e935f09604f3a1580a6e1bcc888d7b
[aai/sparky-be.git] / src / main / java / org / onap / aai / sparky / util / test / Encryptor.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 package org.onap.aai.sparky.util.test;
24
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;
31
32 /**
33  * The Class Encryptor.
34  */
35 public class Encryptor {
36
37   /**
38    * Instantiates a new encryptor.
39    */
40   public Encryptor() {}
41
42   /**
43    * Decrypt value.
44    *
45    * @param value the value
46    * @return the string
47    */
48   public String decryptValue(String value) {
49     String decyptedValue = "";
50
51     try {
52       decyptedValue = Password.deobfuscate(value);
53     } catch (Exception exc) {
54       System.err.println("Cannot decrypt '" + value + "': " + exc.toString());
55     }
56
57     return decyptedValue;
58   }
59
60   /**
61    * Usage.
62    */
63   public static void usage() {
64     usage(null);
65   }
66
67   /**
68    * Usage.
69    *
70    * @param msg the msg
71    */
72   public static void usage(String msg) {
73     if (msg != null) {
74       System.err.println(msg);
75     }
76     System.err.println("Usage: java Encryptor -e value");
77     System.err.println("\tEncrypt the given value");
78     System.err.println("Usage: java Encryptor -d value");
79     System.err.println("\tDecrypt the given value");
80     System.exit(1);
81   }
82
83 }