1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package java.security; 19 20import java.security.spec.InvalidKeySpecException; 21import java.security.spec.KeySpec; 22 23/** 24 * {@code KeyFactorySpi} is the Service Provider Interface (SPI) definition for 25 * {@link KeyFactory}. 26 * 27 * @see KeyFactory 28 */ 29public abstract class KeyFactorySpi { 30 31 /** 32 * Generates a instance of {@code PublicKey} from the given key 33 * specification. 34 * 35 * @param keySpec 36 * the specification of the public key. 37 * @return the public key. 38 * @throws InvalidKeySpecException 39 * if the specified {@code keySpec} is invalid. 40 */ 41 protected abstract PublicKey engineGeneratePublic(KeySpec keySpec) 42 throws InvalidKeySpecException; 43 44 /** 45 * Generates a instance of {@code PrivateKey} from the given key 46 * specification. 47 * 48 * @param keySpec 49 * the specification of the private key. 50 * @return the private key. 51 * @throws InvalidKeySpecException 52 * if the specified {@code keySpec} is invalid. 53 */ 54 protected abstract PrivateKey engineGeneratePrivate(KeySpec keySpec) 55 throws InvalidKeySpecException; 56 57 /** 58 * Returns the key specification for the specified key. 59 * 60 * @param key 61 * the key from which the specification is requested. 62 * @param keySpec 63 * the type of the requested {@code KeySpec}. 64 * @return the key specification for the specified key. 65 * @throws InvalidKeySpecException 66 * if the key can not be processed, or the requested requested 67 * {@code KeySpec} is inappropriate for the given key. 68 */ 69 protected abstract <T extends KeySpec> T engineGetKeySpec(Key key, Class<T> keySpec) 70 throws InvalidKeySpecException; 71 //FIXME 1.5 signature: protected abstract <T extends KeySpec> T engineGetKeySpec(Key key, Class<T> keySpec) throws InvalidKeySpecException 72 73 /** 74 * Translates the given key into a key from this key factory. 75 * 76 * @param key 77 * the key to translate. 78 * @return the translated key. 79 * @throws InvalidKeyException 80 * if the specified key can not be translated by this key 81 * factory. 82 */ 83 protected abstract Key engineTranslateKey(Key key) throws InvalidKeyException; 84 85} 86