📄 cipherspi.java
字号:
/* CipherSpi.java -- The cipher service provider interface. Copyright (C) 2004 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package javax.crypto;import java.security.AlgorithmParameters;import java.security.InvalidAlgorithmParameterException;import java.security.InvalidKeyException;import java.security.Key;import java.security.NoSuchAlgorithmException;import java.security.SecureRandom;import java.security.spec.AlgorithmParameterSpec;/** * <p>This class represents the <i>Service Provider Interface</i> * (<b>SPI</b>) for cryptographic ciphers.</p> * * <p>Providers of cryptographic ciphers must subclass this for every * cipher they implement, implementing the abstract methods as * appropriate, then provide an entry that points to the subclass in * their implementation of {@link java.security.Provider}.</p> * * <p>CipherSpi objects are instantiated along with {@link Cipher}s when * the {@link Cipher#getInstance(java.lang.String)} methods are invoked. * Particular ciphers are referenced by a <i>transformation</i>, which * is a String consisting of the cipher's name or the ciper's name * followed by a mode and a padding. Transformations all follow the * general form:</p> * * <ul> * <li><i>algorithm</i>, or</li> * <li><i>algorithm</i>/<i>mode</i>/<i>padding</i> * </ul> * * <p>Cipher names in the master {@link java.security.Provider} class * may be:</p> * * <ol> * <li>The algorithm's name, which uses a pluggable mode and padding: * <code>Cipher.<i>algorithm</i></code></li> * <li>The algorithm's name and the mode, which uses pluggable padding: * <code>Cipher.<i>algorithm</i>/<i>mode</i></code></li> * <li>The algorithm's name and the padding, which uses a pluggable * mode: <code>Cipher.<i>algorithm</i>//<i>padding</i></code></li> * <li>The algorihtm's name, the mode, and the padding: * <code>Cipher.<i>algorithm</i>/<i>mode</i>/<i>padding</i></code></li> * </ol> * * <p>When any {@link Cipher#getInstance(java.lang.String)} method is * invoked, the following happens if the transformation is simply * <i>algorithm</i>:</p> * * <ol> * <li>If the provider defines a <code>CipherSpi</code> implementation * for "<i>algorithm</i>", return it. Otherwise throw a {@link * java.security.NoSuchAlgorithmException}.</li> * </ol> * * <p>If the transformation is of the form * <i>algorithm</i>/<i>mode</i>/<i>padding</i>:</p> * * <ol> * <li>If the provider defines a <code>CipherSpi</code> subclass for * "<i>algorithm</i>/<i>mode</i>/<i>padding</i>", return it. Otherwise * go to step 2.</li> * * <li>If the provider defines a <code>CipherSpi</code> subclass for * "<i>algorithm</i>/<i>mode</i>", instatiate it, call {@link * #engineSetPadding(java.lang.String)} for the padding name, and return * it. Otherwise go to step 3.</li> * * <li>If the provider defines a <code>CipherSpi</code> subclass for * "<i>algorithm</i>//<i>padding</i>", instatiate it, call {@link * #engineSetMode(java.lang.String)} for the mode name, and return * it. Otherwise go to step 4.</li> * * <li>If the provider defines a <code>CipherSpi</code> subclass for * "<i>algorithm</i>", instatiate it, call {@link * #engineSetMode(java.lang.String)} for the mode name, call {@link * #engineSetPadding(java.lang.String)} for the padding name, and return * it. Otherwise throw a {@link java.security.NoSuchAlgorithmException}.</li> * </ol> * * @author Casey Marshall (csm@gnu.org) * @since 1.4 */public abstract class CipherSpi{ // Constructors. // ------------------------------------------------------------------------ /** * Create a new CipherSpi. */ public CipherSpi() { } // Abstract methods to be implemented by providers. // ------------------------------------------------------------------------ /** * Finishes a multi-part transformation or transforms a portion of a * byte array, and returns the transformed bytes. * * @param input The input bytes. * @param inputOffset The index in the input at which to start. * @param inputLength The number of bytes to transform. * @return The transformed bytes in a new array. * @throws javax.crypto.IllegalBlockSizeException If this instance has * no padding and the input size is not a multiple of the * block size. * @throws javax.crypto.BadPaddingException If this instance is being * used for decryption and the padding is not appropriate for * this instance's padding scheme. */ protected abstract byte[] engineDoFinal(byte[] input, int inputOffset, int inputLength) throws IllegalBlockSizeException, BadPaddingException; /** * Finishes a multi-part transformation or transforms a portion of a * byte array, and stores the transformed bytes in the supplied array. * * @param input The input bytes. * @param inputOffset The index in the input at which to start. * @param inputLength The number of bytes to transform. * @param output The output byte array. * @param outputOffset The index in the output array at which to start. * @return The number of transformed bytes stored in the output array. * @throws javax.crypto.IllegalBlockSizeException If this instance has * no padding and the input size is not a multiple of the * block size. * @throws javax.crypto.BadPaddingException If this instance is being * used for decryption and the padding is not appropriate for * this instance's padding scheme. * @throws javax.crypto.ShortBufferException If there is not enough * space in the output array for the transformed bytes. */ protected abstract int engineDoFinal(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset) throws IllegalBlockSizeException, BadPaddingException, ShortBufferException; /** * Returns the block size of the underlying cipher. * * @return The block size. */ protected abstract int engineGetBlockSize(); /** * Returns the initializaiton vector this cipher was initialized with, * if any. * * @return The IV, or null if this cipher uses no IV or if this * instance has not been initialized yet. */ protected abstract byte[] engineGetIV(); /** * <p>Return the length of the given key in bits.</p> * * <p>For compatibility this method is not declared
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -