KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > schlichtherle > key > passwd > console > PromptingAesKeyProviderUI


1 /*
2  * Copyright 2006 Schlichtherle IT Services
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
17 package de.schlichtherle.key.passwd.console;
18
19 import de.schlichtherle.key.*;
20
21 import java.io.*;
22
23 /**
24  * Extends its base class to enable the user to select the key strength
25  * for the AES cipher.
26  * This class is thread safe.
27  *
28  * @author Christian Schlichtherle
29  * @since TrueZIP 6.4
30  * @version @version@
31  */

32 public class PromptingAesKeyProviderUI extends PromptingKeyProviderUI {
33
34     protected void promptExtraData(PromptingKeyProvider provider) {
35         // We can safely cast the parameter to PromptingAesKeyProvider, because
36
// otherwise we would not have been called.
37
final PromptingAesKeyProvider aesKeyProvider = ((PromptingAesKeyProvider) provider);
38
39         printf(resources.getString("keyStrength.banner"));
40         printf(resources.getString("keyStrength.medium"));
41         printf(resources.getString("keyStrength.high"));
42         printf(resources.getString("keyStrength.ultra"));
43
44         prompting: while (true) {
45             String JavaDoc keyStrength = readLine(
46                     resources.getString("keyStrength.prompt"),
47                     aesKeyProvider);
48             if (keyStrength == null || keyStrength.length() <= 0)
49                 return;
50             try {
51                 switch (Integer.parseInt(keyStrength)) {
52                     case 128:
53                         aesKeyProvider.setKeyStrength(
54                                 AesKeyProvider.KEY_STRENGTH_128);
55                         break prompting;
56
57                     case 192:
58                         aesKeyProvider.setKeyStrength(
59                                 AesKeyProvider.KEY_STRENGTH_192);
60                         break prompting;
61
62                     case 256:
63                         aesKeyProvider.setKeyStrength(
64                                 AesKeyProvider.KEY_STRENGTH_256);
65                         break prompting;
66                 }
67             } catch (NumberFormatException JavaDoc syntaxError) {
68             }
69         }
70     }
71 }
Popular Tags