1 7 8 package javax.security.auth.kerberos; 9 10 import javax.crypto.SecretKey; 11 import javax.security.auth.Destroyable ; 12 import javax.security.auth.DestroyFailedException ; 13 14 40 public class KerberosKey implements SecretKey, Destroyable { 41 42 private static final long serialVersionUID = -4625402278148246993L; 43 44 49 private KerberosPrincipal principal; 50 51 56 private int versionNum; 57 58 71 72 private KeyImpl key; 73 private transient boolean destroyed = false; 74 75 86 public KerberosKey(KerberosPrincipal principal, 87 byte[] keyBytes, 88 int keyType, 89 int versionNum) { 90 this.principal = principal; 91 this.versionNum = versionNum; 92 key = new KeyImpl (keyBytes, keyType); 93 } 94 95 106 public KerberosKey(KerberosPrincipal principal, 107 char[] password, 108 String algorithm) { 109 110 this.principal = principal; 111 key = new KeyImpl (principal, password, algorithm); 113 } 114 115 120 public final KerberosPrincipal getPrincipal() { 121 if (destroyed) 122 throw new IllegalStateException ("This key is no longer valid"); 123 return principal; 124 } 125 126 131 public final int getVersionNumber() { 132 if (destroyed) 133 throw new IllegalStateException ("This key is no longer valid"); 134 return versionNum; 135 } 136 137 142 public final int getKeyType() { 143 if (destroyed) 144 throw new IllegalStateException ("This key is no longer valid"); 145 return key.getKeyType(); 146 } 147 148 151 152 163 public final String getAlgorithm() { 164 if (destroyed) 165 throw new IllegalStateException ("This key is no longer valid"); 166 return key.getAlgorithm(); 167 } 168 169 174 public final String getFormat() { 175 if (destroyed) 176 throw new IllegalStateException ("This key is no longer valid"); 177 return key.getFormat(); 178 } 179 180 185 public final byte[] getEncoded() { 186 if (destroyed) 187 throw new IllegalStateException ("This key is no longer valid"); 188 return key.getEncoded(); 189 } 190 191 198 public void destroy() throws DestroyFailedException { 199 if (!destroyed) { 200 key.destroy(); 201 principal = null; 202 destroyed = true; 203 } 204 } 205 206 207 208 public boolean isDestroyed() { 209 return destroyed; 210 } 211 212 public String toString() { 213 214 return "Kerberos Principal " + principal.toString() + 215 "Key Version " + versionNum + 216 "key " + key.toString(); 217 } 218 219 } 220 | Popular Tags |