J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package javax.crypto; |
| 27 | |
| 28 | import java.security.*; |
| 29 | import java.security.spec.*; |
| 30 | |
| 31 | /** |
| 32 | * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) |
| 33 | * for the <code>SecretKeyFactory</code> class. |
| 34 | * All the abstract methods in this class must be implemented by each |
| 35 | * cryptographic service provider who wishes to supply the implementation |
| 36 | * of a secret-key factory for a particular algorithm. |
| 37 | * |
| 38 | * <P> A provider should document all the key specifications supported by its |
| 39 | * secret key factory. |
| 40 | * For example, the DES secret-key factory supplied by the "SunJCE" provider |
| 41 | * supports <code>DESKeySpec</code> as a transparent representation of DES |
| 42 | * keys, and that provider's secret-key factory for Triple DES keys supports |
| 43 | * <code>DESedeKeySpec</code> as a transparent representation of Triple DES |
| 44 | * keys. |
| 45 | * |
| 46 | * @author Jan Luehe |
| 47 | * |
| 48 | * @see SecretKey |
| 49 | * @see javax.crypto.spec.DESKeySpec |
| 50 | * @see javax.crypto.spec.DESedeKeySpec |
| 51 | * @since 1.4 |
| 52 | */ |
| 53 | |
| 54 | public abstract class SecretKeyFactorySpi { |
| 55 | |
| 56 | /** |
| 57 | * Generates a <code>SecretKey</code> object from the |
| 58 | * provided key specification (key material). |
| 59 | * |
| 60 | * @param keySpec the specification (key material) of the secret key |
| 61 | * |
| 62 | * @return the secret key |
| 63 | * |
| 64 | * @exception InvalidKeySpecException if the given key specification |
| 65 | * is inappropriate for this secret-key factory to produce a secret key. |
| 66 | */ |
| 67 | protected abstract SecretKey engineGenerateSecret(KeySpec keySpec) |
| 68 | throws InvalidKeySpecException; |
| 69 | |
| 70 | /** |
| 71 | * Returns a specification (key material) of the given key |
| 72 | * object in the requested format. |
| 73 | * |
| 74 | * @param key the key |
| 75 | * |
| 76 | * @param keySpec the requested format in which the key material shall be |
| 77 | * returned |
| 78 | * |
| 79 | * @return the underlying key specification (key material) in the |
| 80 | * requested format |
| 81 | * |
| 82 | * @exception InvalidKeySpecException if the requested key specification is |
| 83 | * inappropriate for the given key (e.g., the algorithms associated with |
| 84 | * <code>key</code> and <code>keySpec</code> do not match, or |
| 85 | * <code>key</code> references a key on a cryptographic hardware device |
| 86 | * whereas <code>keySpec</code> is the specification of a software-based |
| 87 | * key), or the given key cannot be dealt with |
| 88 | * (e.g., the given key has an algorithm or format not supported by this |
| 89 | * secret-key factory). |
| 90 | */ |
| 91 | protected abstract KeySpec engineGetKeySpec(SecretKey key, Class keySpec) |
| 92 | throws InvalidKeySpecException; |
| 93 | |
| 94 | /** |
| 95 | * Translates a key object, whose provider may be unknown or |
| 96 | * potentially untrusted, into a corresponding key object of this |
| 97 | * secret-key factory. |
| 98 | * |
| 99 | * @param key the key whose provider is unknown or untrusted |
| 100 | * |
| 101 | * @return the translated key |
| 102 | * |
| 103 | * @exception InvalidKeyException if the given key cannot be processed |
| 104 | * by this secret-key factory. |
| 105 | */ |
| 106 | protected abstract SecretKey engineTranslateKey(SecretKey key) |
| 107 | throws InvalidKeyException; |
| 108 | } |