Path: blob/master/src/java.base/share/classes/javax/crypto/SecretKeyFactorySpi.java
41152 views
/*1* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.crypto;2627import java.security.*;28import java.security.spec.*;2930/**31* This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)32* for the <code>SecretKeyFactory</code> class.33* All the abstract methods in this class must be implemented by each34* cryptographic service provider who wishes to supply the implementation35* of a secret-key factory for a particular algorithm.36*37* <P> A provider should document all the key specifications supported by its38* secret key factory.39* For example, the DES secret-key factory supplied by the "SunJCE" provider40* supports <code>DESKeySpec</code> as a transparent representation of DES41* keys, and that provider's secret-key factory for Triple DES keys supports42* <code>DESedeKeySpec</code> as a transparent representation of Triple DES43* keys.44*45* @author Jan Luehe46*47* @see SecretKey48* @see javax.crypto.spec.DESKeySpec49* @see javax.crypto.spec.DESedeKeySpec50* @since 1.451*/5253public abstract class SecretKeyFactorySpi {5455/**56* Constructor for subclasses to call.57*/58public SecretKeyFactorySpi() {}5960/**61* Generates a <code>SecretKey</code> object from the62* provided key specification (key material).63*64* @param keySpec the specification (key material) of the secret key65*66* @return the secret key67*68* @exception InvalidKeySpecException if the given key specification69* is inappropriate for this secret-key factory to produce a secret key.70*/71protected abstract SecretKey engineGenerateSecret(KeySpec keySpec)72throws InvalidKeySpecException;7374/**75* Returns a specification (key material) of the given key76* object in the requested format.77*78* @param key the key79*80* @param keySpec the requested format in which the key material shall be81* returned82*83* @return the underlying key specification (key material) in the84* requested format85*86* @exception InvalidKeySpecException if the requested key specification is87* inappropriate for the given key (e.g., the algorithms associated with88* <code>key</code> and <code>keySpec</code> do not match, or89* <code>key</code> references a key on a cryptographic hardware device90* whereas <code>keySpec</code> is the specification of a software-based91* key), or the given key cannot be dealt with92* (e.g., the given key has an algorithm or format not supported by this93* secret-key factory).94*/95protected abstract KeySpec engineGetKeySpec(SecretKey key, Class<?> keySpec)96throws InvalidKeySpecException;9798/**99* Translates a key object, whose provider may be unknown or100* potentially untrusted, into a corresponding key object of this101* secret-key factory.102*103* @param key the key whose provider is unknown or untrusted104*105* @return the translated key106*107* @exception InvalidKeyException if the given key cannot be processed108* by this secret-key factory.109*/110protected abstract SecretKey engineTranslateKey(SecretKey key)111throws InvalidKeyException;112}113114115