Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/security/KeyFactorySpi.java
38829 views
/*1* Copyright (c) 1997, 2013, 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 java.security;2627import java.security.spec.KeySpec;28import java.security.spec.InvalidKeySpecException;2930/**31* This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)32* for the {@code KeyFactory} 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 key factory for a particular algorithm.36*37* <P> Key factories are used to convert <I>keys</I> (opaque38* cryptographic keys of type {@code Key}) into <I>key specifications</I>39* (transparent representations of the underlying key material), and vice40* versa.41*42* <P> Key factories are bi-directional. That is, they allow you to build an43* opaque key object from a given key specification (key material), or to44* retrieve the underlying key material of a key object in a suitable format.45*46* <P> Multiple compatible key specifications may exist for the same key.47* For example, a DSA public key may be specified using48* {@code DSAPublicKeySpec} or49* {@code X509EncodedKeySpec}. A key factory can be used to translate50* between compatible key specifications.51*52* <P> A provider should document all the key specifications supported by its53* key factory.54*55* @author Jan Luehe56*57*58* @see KeyFactory59* @see Key60* @see PublicKey61* @see PrivateKey62* @see java.security.spec.KeySpec63* @see java.security.spec.DSAPublicKeySpec64* @see java.security.spec.X509EncodedKeySpec65*66* @since 1.267*/6869public abstract class KeyFactorySpi {7071/**72* Generates a public key object from the provided key73* specification (key material).74*75* @param keySpec the specification (key material) of the public key.76*77* @return the public key.78*79* @exception InvalidKeySpecException if the given key specification80* is inappropriate for this key factory to produce a public key.81*/82protected abstract PublicKey engineGeneratePublic(KeySpec keySpec)83throws InvalidKeySpecException;8485/**86* Generates a private key object from the provided key87* specification (key material).88*89* @param keySpec the specification (key material) of the private key.90*91* @return the private key.92*93* @exception InvalidKeySpecException if the given key specification94* is inappropriate for this key factory to produce a private key.95*/96protected abstract PrivateKey engineGeneratePrivate(KeySpec keySpec)97throws InvalidKeySpecException;9899/**100* Returns a specification (key material) of the given key101* object.102* {@code keySpec} identifies the specification class in which103* the key material should be returned. It could, for example, be104* {@code DSAPublicKeySpec.class}, to indicate that the105* key material should be returned in an instance of the106* {@code DSAPublicKeySpec} class.107*108* @param <T> the type of the key specification to be returned109*110* @param key the key.111*112* @param keySpec the specification class in which113* the key material should be returned.114*115* @return the underlying key specification (key material) in an instance116* of the requested specification class.117118* @exception InvalidKeySpecException if the requested key specification is119* inappropriate for the given key, or the given key cannot be dealt with120* (e.g., the given key has an unrecognized format).121*/122protected abstract <T extends KeySpec>123T engineGetKeySpec(Key key, Class<T> keySpec)124throws InvalidKeySpecException;125126/**127* Translates a key object, whose provider may be unknown or128* potentially untrusted, into a corresponding key object of this key129* factory.130*131* @param key the key whose provider is unknown or untrusted.132*133* @return the translated key.134*135* @exception InvalidKeyException if the given key cannot be processed136* by this key factory.137*/138protected abstract Key engineTranslateKey(Key key)139throws InvalidKeyException;140141}142143144