KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > schlichtherle > key > PromptingAesKeyProvider


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;
18
19 /**
20  * An implementation of {@link AesKeyProvider} which prompts the user for
21  * a key and allows to select the cipher key strength when creating a new
22  * AES encrypted resource or replacing the entire contents of an already
23  * existing AES encrypted resource.
24  * <p>
25  * This class is thread safe.
26  *
27  * @author Christian Schlichtherle
28  * @version @version@
29  * @since TrueZIP 6.0
30  */

31 public class PromptingAesKeyProvider
32         extends PromptingKeyProvider
33         implements AesKeyProvider {
34
35     private int keyStrength = KEY_STRENGTH_256;
36
37     public int getKeyStrength() {
38         assert keyStrength == KEY_STRENGTH_128
39                 || keyStrength == KEY_STRENGTH_192
40                 || keyStrength == KEY_STRENGTH_256;
41         return keyStrength;
42     }
43
44     public void setKeyStrength(int keyStrength) {
45         if (keyStrength != KEY_STRENGTH_128
46                 && keyStrength != KEY_STRENGTH_192
47                 && keyStrength != KEY_STRENGTH_256)
48             throw new IllegalArgumentException JavaDoc();
49         this.keyStrength = keyStrength;
50     }
51
52     protected String JavaDoc getUIClassID() {
53         return "PromptingAesKeyProvider"; // support code obfuscation!
54
}
55
56     /**
57      * Resets the key strength to 256 bits.
58      */

59     protected void onReset() {
60         keyStrength = KEY_STRENGTH_256;
61     }
62
63     /**
64      * Returns the current key strength.
65      */

66     public String JavaDoc toString() {
67         return "" + (128 + keyStrength * 64);
68     }
69 }
Popular Tags