KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > schlichtherle > key > passwd > swing > AesKeyMgmtLifeCycle


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.swing;
18
19 import de.schlichtherle.key.*;
20
21 import java.util.logging.*;
22
23 /**
24  * @author Christian Schlichtherle
25  * @version @version@
26  * @since TrueZIP 6.1
27  */

28 public class AesKeyMgmtLifeCycle extends KeyMgmtLifeCycle {
29
30     private static final Logger logger
31             = Logger.getLogger(AesKeyMgmtLifeCycle.class.getName());
32
33     private int keyStrength;
34
35     /**
36      * @param id The identifier of the protected resource.
37      */

38     public AesKeyMgmtLifeCycle(final String JavaDoc id) {
39         super(id);
40     }
41
42     protected KeyProvider getKeyProvider(KeyManager manager, String JavaDoc id) {
43         return manager.getKeyProvider(id, AesKeyProvider.class);
44     }
45
46     protected void createResourceHook(KeyProvider provider) {
47         // In a real world application, you should never blindly cast
48
// a key provider.
49
this.keyStrength = ((AesKeyProvider) provider).getKeyStrength();
50
51         printKeyStrength(provider);
52     }
53
54     protected void openResourceHook(KeyProvider provider) {
55         // In a real world application, you should never blindly cast
56
// a key provider.
57
((AesKeyProvider) provider).setKeyStrength(keyStrength);
58
59         printKeyStrength(provider);
60     }
61
62     private void printKeyStrength(KeyProvider provider) {
63         String JavaDoc msg = id + ": key strength is ";
64         switch(keyStrength) {
65             case AesKeyProvider.KEY_STRENGTH_128:
66
67                 msg += "128";
68
69                 break;
70             case AesKeyProvider.KEY_STRENGTH_192:
71
72                 msg += "192";
73
74                 break;
75             case AesKeyProvider.KEY_STRENGTH_256:
76
77                 msg += "256";
78
79                 break;
80             default:
81
82                 throw new AssertionError JavaDoc("Illegal key strength!");
83         }
84         msg += " bits.";
85         logger.fine(msg);
86     }
87 }
Popular Tags