View Javadoc
1   /*
2    * Copyright 2013 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.juddi.v3.client.cryptor;
17  
18  /**
19   * A static entry point for encrypting text via CLI
20   *
21   * @since 3.1.5
22   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
23   * @see CryptorFactory
24   */
25  public class CryptorUtil {
26  
27          public static void main(String[] args) throws Exception {
28                  if (args.length == 0) {
29                          PrintUsage();
30                          return;
31                  }
32                  Cryptor cryptor = CryptorFactory.getCryptor(args[0]);
33                  if (System.getProperty("generate", "false").equalsIgnoreCase("true")) {
34                          System.out.println("Generating new key...");
35                          System.out.println(cryptor.newKey());
36                  } else {
37                          System.out.print("Password: ");
38                          char[] readPassword = System.console().readPassword();
39                          System.out.println("Cipher: " + cryptor.encrypt(new String(readPassword)));
40                  }
41          }
42  
43          private static void PrintUsage() {
44                  System.out.println("Encrypts a password using the specified crypto provider");
45                  System.out.println("Usage: java (options) -cp (classpath) " + CryptorUtil.class.getCanonicalName() + " (CryptoProvider)");
46  
47                  System.out.println("Provided crypto providers:");
48                  System.out.println("\t" + DefaultCryptor.class.getCanonicalName() + " - uses PBEWithMD5AndDES");
49                  System.out.println("\t" + TripleDESCrytor.class.getCanonicalName() + " - uses TripleDES");
50                  System.out.println("\t" + AES128Cryptor.class.getCanonicalName() + " - uses AES128");
51                  System.out.println("\t" + AES256Cryptor.class.getCanonicalName() + " - uses AES256*");
52                  System.out.println();
53                  System.out.println("* Requires Unlimited Strength JCE *");
54                  System.out.println();
55                  System.out.println("Available options:");
56                  System.out.println("\t-Dgenerate=true - generates a new encryption key and writes to std out");
57                  System.out.println("\t-Djuddi.encryptionKeyFile.(providerClassName)=path - encrypts a password using the specified key");
58                  System.out.println("(e.g. -Djuddi.encryptionKeyFile.TripleDESCrytor,-Djuddi.encryptionKeyFile.AES128Cryptor, etc ");
59          }
60  }