Top Inners Fields Constructors Methods
org.bouncycastle.jcajce.provider.asymmetric.util

public abstract Class BaseCipherSpi

extends CipherSpi
Class Inheritance
Known Direct Subclasses
org.bouncycastle.jcajce.provider.asymmetric.dh.IESCipher, org.bouncycastle.jcajce.provider.asymmetric.ec.IESCipher, org.bouncycastle.jcajce.provider.asymmetric.ec.IESKEMCipher, org.bouncycastle.jcajce.provider.asymmetric.edec.IESCipher, org.bouncycastle.jcajce.provider.asymmetric.elgamal.CipherSpi, org.bouncycastle.jcajce.provider.asymmetric.rsa.CipherSpi
Imports
java.io.ByteArrayOutputStream, java.security.AlgorithmParameters, .InvalidKeyException, .Key, .KeyFactory, .NoSuchAlgorithmException, .NoSuchProviderException, .PrivateKey, java.security.spec.InvalidKeySpecException, .PKCS8EncodedKeySpec, .X509EncodedKeySpec, javax.crypto.BadPaddingException, .Cipher, .CipherSpi, .IllegalBlockSizeException, .NoSuchPaddingException, javax.crypto.spec.IvParameterSpec, .PBEParameterSpec, .RC2ParameterSpec, .RC5ParameterSpec, .SecretKeySpec, org.bouncycastle.asn1.pkcs.PrivateKeyInfo, org.bouncycastle.crypto.InvalidCipherTextException, .Wrapper, org.bouncycastle.jcajce.util.BCJcaJceHelper, .JcaJceHelper, org.bouncycastle.jce.provider.BouncyCastleProvider, org.bouncycastle.util.Arrays

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class

Field Summary

Modifier and TypeField and Description
private Class<T>[]
protected AlgorithmParameters
private final JcaJceHelper
private byte[]
private int
protected Wrapper

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected final AlgorithmParameters
protected int
engineGetBlockSize()

Implements abstract javax.crypto.CipherSpi.engineGetBlockSize.

Returns the block size (in bytes).

protected byte[]
engineGetIV()

Implements abstract javax.crypto.CipherSpi.engineGetIV.

Returns the initialization vector (IV) in a new buffer.

protected int
engineGetKeySize(Key
the key object
key
)

Overrides javax.crypto.CipherSpi.engineGetKeySize.

Returns the key size of the given key object in bits.

protected int
engineGetOutputSize(int
the input length (in bytes)
inputLen
)

Implements abstract javax.crypto.CipherSpi.engineGetOutputSize.

Returns the length in bytes that an output buffer would need to be in order to hold the result of the next update or doFinal operation, given the input length inputLen (in bytes).

protected AlgorithmParameters
engineGetParameters()

Implements abstract javax.crypto.CipherSpi.engineGetParameters.

Returns the parameters used with this cipher.

protected void
engineSetMode(String
the cipher mode
mode
)

Implements abstract javax.crypto.CipherSpi.engineSetMode.

Sets the mode of this cipher.

protected void
engineSetPadding(String
the padding mechanism
padding
)

Implements abstract javax.crypto.CipherSpi.engineSetPadding.

Sets the padding mechanism of this cipher.

protected Key
engineUnwrap(byte[]
the key to be unwrapped
wrappedKey
,
String
the algorithm associated with the wrapped key
wrappedKeyAlgorithm
,
int
the type of the wrapped key. This is one of SECRET_KEY, PRIVATE_KEY, or PUBLIC_KEY.
wrappedKeyType
)

Overrides javax.crypto.CipherSpi.engineUnwrap.

Unwrap a previously wrapped key.

protected byte[]
engineWrap(Key
the key to be wrapped
key
)

Overrides javax.crypto.CipherSpi.engineWrap.

Wrap a key.

Inherited from javax.crypto.CipherSpi:
engineDoFinalengineDoFinalengineDoFinalengineInitengineInitengineInitengineUpdateengineUpdateengineUpdateengineUpdateAADengineUpdateAAD

Field Detail

availableSpecsback to summary
private Class<T>[] availableSpecs
engineParamsback to summary
protected AlgorithmParameters engineParams
helperback to summary
private final JcaJceHelper helper
ivback to summary
private byte[] iv
ivSizeback to summary
private int ivSize
wrapEngineback to summary
protected Wrapper wrapEngine

Constructor Detail

BaseCipherSpiback to summary
protected BaseCipherSpi()

Method Detail

createParametersInstanceback to summary
protected final AlgorithmParameters createParametersInstance(String algorithm) throws NoSuchAlgorithmException, NoSuchProviderException
engineGetBlockSizeback to summary
protected int engineGetBlockSize()

Implements abstract javax.crypto.CipherSpi.engineGetBlockSize.

Doc from javax.crypto.CipherSpi.engineGetBlockSize.

Returns the block size (in bytes).

Returns:int

the block size (in bytes), or 0 if the algorithm is not a block cipher

engineGetIVback to summary
protected byte[] engineGetIV()

Implements abstract javax.crypto.CipherSpi.engineGetIV.

Doc from javax.crypto.CipherSpi.engineGetIV.

Returns the initialization vector (IV) in a new buffer.

This is useful in the context of password-based encryption or decryption, where the IV is derived from a user-provided passphrase.

Returns:byte[]

the initialization vector in a new buffer, or null if the algorithm does not use an IV, or if the IV has not yet been set

engineGetKeySizeback to summary
protected int engineGetKeySize(Key key)

Overrides javax.crypto.CipherSpi.engineGetKeySize.

Doc from javax.crypto.CipherSpi.engineGetKeySize.

Returns the key size of the given key object in bits.

This concrete method has been added to this previously-defined abstract class. It throws an UnsupportedOperationException if it is not overridden by the provider.

Parameters
key:Key

the key object

Returns:int

the key size of the given key object

engineGetOutputSizeback to summary
protected int engineGetOutputSize(int inputLen)

Implements abstract javax.crypto.CipherSpi.engineGetOutputSize.

Doc from javax.crypto.CipherSpi.engineGetOutputSize.

Returns the length in bytes that an output buffer would need to be in order to hold the result of the next update or doFinal operation, given the input length inputLen (in bytes).

This call takes into account any unprocessed (buffered) data from a previous update call, padding, and AEAD tagging.

The actual output length of the next update or doFinal call may be smaller than the length returned by this method.

Parameters
inputLen:int

the input length (in bytes)

Returns:int

the required output buffer size (in bytes)

engineGetParametersback to summary
protected AlgorithmParameters engineGetParameters()

Implements abstract javax.crypto.CipherSpi.engineGetParameters.

Doc from javax.crypto.CipherSpi.engineGetParameters.

Returns the parameters used with this cipher.

The returned parameters may be the same that were used to initialize this cipher, or may contain additional default or random parameter values used by the underlying cipher implementation. If the required parameters were not supplied and can be generated by the cipher, the generated parameters are returned. Otherwise, null is returned.

Returns:AlgorithmParameters

the parameters used with this cipher, or null

engineSetModeback to summary
protected void engineSetMode(String mode) throws NoSuchAlgorithmException

Implements abstract javax.crypto.CipherSpi.engineSetMode.

Doc from javax.crypto.CipherSpi.engineSetMode.

Sets the mode of this cipher.

Parameters
mode:String

the cipher mode

Exceptions
NoSuchAlgorithmException:
if the requested cipher mode does not exist
engineSetPaddingback to summary
protected void engineSetPadding(String padding) throws NoSuchPaddingException

Implements abstract javax.crypto.CipherSpi.engineSetPadding.

Doc from javax.crypto.CipherSpi.engineSetPadding.

Sets the padding mechanism of this cipher.

Parameters
padding:String

the padding mechanism

Exceptions
NoSuchPaddingException:
if the requested padding mechanism does not exist
engineUnwrapback to summary
protected Key engineUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType) throws InvalidKeyException

Overrides javax.crypto.CipherSpi.engineUnwrap.

Doc from javax.crypto.CipherSpi.engineUnwrap.

Unwrap a previously wrapped key.

This concrete method has been added to this previously-defined abstract class. (For backwards compatibility, it cannot be abstract.) It may be overridden by a provider to unwrap a previously wrapped key. Such an override is expected to throw an InvalidKeyException if the given wrapped key cannot be unwrapped. If this method is not overridden, it always throws an UnsupportedOperationException.

Parameters
wrappedKey:byte[]

the key to be unwrapped

wrappedKeyAlgorithm:String

the algorithm associated with the wrapped key

wrappedKeyType:int

the type of the wrapped key. This is one of SECRET_KEY, PRIVATE_KEY, or PUBLIC_KEY.

Returns:Key

the unwrapped key

Exceptions
InvalidKeyException:
if wrappedKey does not represent a wrapped key of type wrappedKeyType for the wrappedKeyAlgorithm
engineWrapback to summary
protected byte[] engineWrap(Key key) throws IllegalBlockSizeException, InvalidKeyException

Overrides javax.crypto.CipherSpi.engineWrap.

Doc from javax.crypto.CipherSpi.engineWrap.

Wrap a key.

This concrete method has been added to this previously-defined abstract class. (For backwards compatibility, it cannot be abstract.) It may be overridden by a provider to wrap a key. Such an override is expected to throw an IllegalBlockSizeException or InvalidKeyException (under the specified circumstances), if the given key cannot be wrapped. If this method is not overridden, it always throws an UnsupportedOperationException.

Parameters
key:Key

the key to be wrapped

Returns:byte[]

the wrapped key

Exceptions
IllegalBlockSizeException:
if this cipher is a block cipher, no padding has been requested, and the length of the encoding of the key to be wrapped is not a multiple of the block size
InvalidKeyException:
if it is impossible or unsafe to wrap the key with this cipher (e.g., a hardware protected key is being passed to a software-only cipher)
org.bouncycastle.jcajce.provider.asymmetric.util back to summary

protected final Class BaseCipherSpi.ErasableOutputStream

extends ByteArrayOutputStream
Class Inheritance

Field Summary

Inherited from java.io.ByteArrayOutputStream:
bufcount

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public byte[]
Inherited from java.io.ByteArrayOutputStream:
closeresetsizetoByteArraytoStringtoStringtoStringtoStringwritewritewriteByteswriteTo

Constructor Detail

ErasableOutputStreamback to summary
public ErasableOutputStream()

Method Detail

eraseback to summary
public void erase()
getBufback to summary
public byte[] getBuf()