/* * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.security.auth.kerberos; import java.util.Arrays; import java.util.Objects; import javax.crypto.SecretKey; import javax.security.auth.DestroyFailedException; /** * This class encapsulates an EncryptionKey used in Kerberos.
* * An EncryptionKey is defined in Section 4.2.9 of the Kerberos Protocol * Specification (RFC 4120) as: *
* EncryptionKey ::= SEQUENCE { * keytype [0] Int32 -- actually encryption type --, * keyvalue [1] OCTET STRING * } ** The key material of an {@code EncryptionKey} is defined as the value * of the {@code keyValue} above. * * @since 9 */ public final class EncryptionKey implements SecretKey { private static final long serialVersionUID = 9L; /** * {@code KeyImpl} is serialized by writing out the ASN.1 encoded bytes * of the encryption key. * * @serial */ final private KeyImpl key; private transient boolean destroyed = false; /** * Constructs a {@code EncryptionKey} from the given bytes and * the key type. *
* The contents of the byte array are copied; subsequent modification of * the byte array does not affect the newly created key. * * @param keyBytes the key material for the key * @param keyType the key type for the key as defined by the * Kerberos protocol specification. * @throws NullPointerException if keyBytes is null */ public EncryptionKey(byte[] keyBytes, int keyType) { key = new KeyImpl(Objects.requireNonNull(keyBytes), keyType); } /** * Returns the key type for this key. * * @return the key type. * @throws IllegalStateException if the key is destroyed */ public int getKeyType() { // KeyImpl already checked if destroyed return key.getKeyType(); } /* * Methods from java.security.Key */ /** * Returns the standard algorithm name for this key. The algorithm names * are the encryption type string defined on the IANA * Kerberos Encryption Type Numbers * page. *
* This method can return the following value not defined on the IANA page: *