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 at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */16package org.apache.juddi.v3.client.cryptor;
1718/**19 * A static entry point for encrypting text via CLI20 *21 * @since 3.1.522 * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>23 * @see CryptorFactory24 */25publicclassCryptorUtil {
2627publicstaticvoid main(String[] args) throws Exception {
28if (args.length == 0) {
29 PrintUsage();
30return;
31 }
32Cryptor cryptor = CryptorFactory.getCryptor(args[0]);
33if (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: ");
38char[] readPassword = System.console().readPassword();
39 System.out.println("Cipher: " + cryptor.encrypt(new String(readPassword)));
40 }
41 }
4243privatestaticvoid 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)");
4647 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 }