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

pack-priv Class BaseSingleBlockCipher

extends CipherSpi
Class Inheritance
Imports
java.security.AccessController, .AlgorithmParameters, .InvalidAlgorithmParameterException, .InvalidKeyException, .InvalidParameterException, .Key, .NoSuchAlgorithmException, .PrivateKey, .PrivilegedAction, .PublicKey, .SecureRandom, java.security.interfaces.RSAKey, .RSAPrivateKey, .RSAPublicKey, java.security.spec.AlgorithmParameterSpec, .InvalidParameterSpecException, .MGF1ParameterSpec, java.util.Arrays, .HashMap, .HashSet, .Map, .Set, javax.crypto.BadPaddingException, .Cipher, .CipherSpi, .IllegalBlockSizeException, .NoSuchPaddingException, .ShortBufferException, javax.crypto.interfaces.DHKey, .DHPrivateKey, .DHPublicKey, javax.crypto.spec.OAEPParameterSpec, .PSource, org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers, org.bouncycastle.crypto.Algorithm, .AsymmetricKey, .AsymmetricOperatorFactory, .InvalidCipherTextException, .InvalidWrappingException, .KeyUnwrapper, .KeyWrapOperatorFactory, .KeyWrapper, .Parameters, .PlainInputProcessingException, .SingleBlockCipher, .SingleBlockDecryptor, .SingleBlockEncryptor, org.bouncycastle.crypto.fips.FipsAlgorithm, .FipsKeyWrapOperatorFactory, org.bouncycastle.util.Strings

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private Set<Algorithm>
private final Algorithm[]
private Parameters
private final Class<T>[]
private final Map<Algorithm, Parameters>
private DataArrayOutputStream
private SingleBlockCipher<T extends Parameters>
private AlgorithmParameters
private final FipsKeyWrapOperatorFactory<T extends Parameters, K extends Key>
private final BouncyCastleFipsProvider
private final AsymmetricOperatorFactory<T extends Parameters>
private final KeyWrapOperatorFactory<T extends Parameters, K extends Key>
private KeyUnwrapper<T extends Parameters>
private KeyWrapper<T extends Parameters>
private final ParametersCreatorProvider<T extends Parameters>
private AlgorithmParameterSpec
private final PrivateKeyConverter<T extends AsymmetricPrivateKey>
private boolean
private final PublicKeyConverter<T extends AsymmetricPublicKey>
private boolean
private static final Class<T>
private final boolean

Constructor Summary

AccessConstructor and Description
public
BaseSingleBlockCipher(BouncyCastleFipsProvider fipsProvider, boolean publicKeyOnly, boolean privateKeyOnly, boolean wrapModeOnly, Class<T>[] availableSpecs, AsymmetricOperatorFactory<T extends Parameters> generalFactory, FipsKeyWrapOperatorFactory<T extends Parameters, K extends Key> fipsKeyWrapOperatorFactory, KeyWrapOperatorFactory<T extends Parameters, K extends Key> generalKeyWrapOperatorFactory, PublicKeyConverter<T extends AsymmetricPublicKey> publicKeyConverter, PrivateKeyConverter<T extends AsymmetricPrivateKey> privateKeyConverter, ParametersCreatorProvider<T extends Parameters> parametersCreatorProvider, Map<Algorithm, Parameters> baseParametersMap, Algorithm... algorithms)

Method Summary

Modifier and TypeMethod and Description
private void
protected byte[]
engineDoFinal(byte[]
the input buffer
input
,
int
the offset in input where the input starts
inputOffset
,
int
the input length
inputLen
)

Implements abstract javax.crypto.CipherSpi.engineDoFinal.

Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.
protected int
engineDoFinal(byte[]
the input buffer
input
,
int
the offset in input where the input starts
inputOffset
,
int
the input length
inputLen
,
byte[]
the buffer for the result
output
,
int
the offset in output where the result is stored
outputOffset
)

Implements abstract javax.crypto.CipherSpi.engineDoFinal.

Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.
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
engineInit(int
the operation mode of this CipherSpi object (this is one of the following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE, or UNWRAP_MODE)
opmode
,
Key
the encryption key
key
,
final AlgorithmParameterSpec
the algorithm parameters
params
,
SecureRandom
the source of randomness
random
)

Implements abstract javax.crypto.CipherSpi.engineInit.

Initializes this CipherSpi object with a key, a set of algorithm parameters, and a source of randomness.
protected void
engineInit(int
the operation mode of this CipherSpi object (this is one of the following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE, or UNWRAP_MODE)
opmode
,
Key
the encryption key
key
,
AlgorithmParameters
the algorithm parameters
params
,
SecureRandom
the source of randomness
random
)

Implements abstract javax.crypto.CipherSpi.engineInit.

Initializes this CipherSpi object with a key, a set of algorithm parameters, and a source of randomness.
protected void
engineInit(int
the operation mode of this CipherSpi object (this is one of the following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE)
opmode
,
Key
the encryption key
key
,
SecureRandom
the source of randomness
random
)

Implements abstract javax.crypto.CipherSpi.engineInit.

Initializes this CipherSpi object with a key and a source of randomness.
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[]
engineUpdate(byte[]
the input buffer
input
,
int
the offset in input where the input starts
inputOffset
,
int
the input length
inputLen
)

Implements abstract javax.crypto.CipherSpi.engineUpdate.

Continues a multiple-part encryption or decryption operation (depending on how this CipherSpi object was initialized), processing another data part.
protected int
engineUpdate(byte[]
the input buffer
input
,
int
the offset in input where the input starts
inputOffset
,
int
the input length
inputLen
,
byte[]
the buffer for the result
output
,
int
the offset in output where the result is stored
outputOffset
)

Implements abstract javax.crypto.CipherSpi.engineUpdate.

Continues a multiple-part encryption or decryption operation (depending on how this CipherSpi object was initialized), processing another data part.
protected byte[]
engineWrap(Key
the key to be wrapped
key
)

Overrides javax.crypto.CipherSpi.engineWrap.

Wrap a key.
private byte[]
private void
Inherited from javax.crypto.CipherSpi:
engineDoFinalengineUpdateengineUpdateAADengineUpdateAAD

Field Detail

activeAlgorithmSetback to summary
private Set<Algorithm> activeAlgorithmSet
algorithmsback to summary
private final Algorithm[] algorithms
algParametersback to summary
private Parameters algParameters
availableSpecsback to summary
private final Class<T>[] availableSpecs
baseParametersMapback to summary
private final Map<Algorithm, Parameters> baseParametersMap
bOutback to summary
private DataArrayOutputStream bOut
cipherback to summary
private SingleBlockCipher<T extends Parameters> cipher
engineParamsback to summary
private AlgorithmParameters engineParams
fipsKeyWrapOperatorFactoryback to summary
private final FipsKeyWrapOperatorFactory<T extends Parameters, K extends Key> fipsKeyWrapOperatorFactory
fipsProviderback to summary
private final BouncyCastleFipsProvider fipsProvider
generalFactoryback to summary
private final AsymmetricOperatorFactory<T extends Parameters> generalFactory
generalKeyWrapOperatorFactoryback to summary
private final KeyWrapOperatorFactory<T extends Parameters, K extends Key> generalKeyWrapOperatorFactory
keyUnwrapperback to summary
private KeyUnwrapper<T extends Parameters> keyUnwrapper
keyWrapperback to summary
private KeyWrapper<T extends Parameters> keyWrapper
parametersCreatorProviderback to summary
private final ParametersCreatorProvider<T extends Parameters> parametersCreatorProvider
paramSpecback to summary
private AlgorithmParameterSpec paramSpec
privateKeyConverterback to summary
private final PrivateKeyConverter<T extends AsymmetricPrivateKey> privateKeyConverter
privateKeyOnlyback to summary
private boolean privateKeyOnly
publicKeyConverterback to summary
private final PublicKeyConverter<T extends AsymmetricPublicKey> publicKeyConverter
publicKeyOnlyback to summary
private boolean publicKeyOnly
TlsRsaPremasterSecretParameterSpecback to summary
private static final Class<T> TlsRsaPremasterSecretParameterSpec
wrapModeOnlyback to summary
private final boolean wrapModeOnly

Constructor Detail

BaseSingleBlockCipherback to summary
public BaseSingleBlockCipher(BouncyCastleFipsProvider fipsProvider, boolean publicKeyOnly, boolean privateKeyOnly, boolean wrapModeOnly, Class<T>[] availableSpecs, AsymmetricOperatorFactory<T extends Parameters> generalFactory, FipsKeyWrapOperatorFactory<T extends Parameters, K extends Key> fipsKeyWrapOperatorFactory, KeyWrapOperatorFactory<T extends Parameters, K extends Key> generalKeyWrapOperatorFactory, PublicKeyConverter<T extends AsymmetricPublicKey> publicKeyConverter, PrivateKeyConverter<T extends AsymmetricPrivateKey> privateKeyConverter, ParametersCreatorProvider<T extends Parameters> parametersCreatorProvider, Map<Algorithm, Parameters> baseParametersMap, Algorithm... algorithms)

Method Detail

checkBufferSizeback to summary
private void checkBufferSize()
engineDoFinalback to summary
protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen) throws IllegalBlockSizeException, BadPaddingException

Implements abstract javax.crypto.CipherSpi.engineDoFinal.

Doc from javax.crypto.CipherSpi.engineDoFinal.

Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation. The data is encrypted or decrypted, depending on how this CipherSpi object was initialized.

The first inputLen bytes in the input buffer, starting at inputOffset inclusive, and any input bytes that may have been buffered during a previous update operation, are processed, with padding (if requested) being applied. If an AEAD mode (such as GCM or CCM) is being used, the authentication tag is appended in the case of encryption, or verified in the case of decryption. The result is stored in a new buffer.

Upon finishing, this method resets this CipherSpi object to the state it was in when previously initialized via a call to engineInit. That is, the object is reset and available to encrypt or decrypt (depending on the operation mode that was specified in the call to engineInit) more data.

Note

if any exception is thrown, this CipherSpi object may need to be reset before it can be used again.

Parameters
input:byte[]

the input buffer

inputOffset:int

the offset in input where the input starts

inputLen:int

the input length

Returns:byte[]

the new buffer with the result

Exceptions
IllegalBlockSizeException:
if this cipher is a block cipher, no padding has been requested (only in encryption mode), and the total input length of the data processed by this cipher is not a multiple of block size; or if this encryption algorithm is unable to process the input data provided
BadPaddingException:
if this CipherSpi object is in decryption mode, and (un)padding has been requested, but the decrypted data is not bounded by the appropriate padding bytes
engineDoFinalback to summary
protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws IllegalBlockSizeException, BadPaddingException, ShortBufferException

Implements abstract javax.crypto.CipherSpi.engineDoFinal.

Doc from javax.crypto.CipherSpi.engineDoFinal.

Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation. The data is encrypted or decrypted, depending on how this CipherSpi object was initialized.

The first inputLen bytes in the input buffer, starting at inputOffset inclusive, and any input bytes that may have been buffered during a previous update operation, are processed, with padding (if requested) being applied. If an AEAD mode such as GCM or CCM is being used, the authentication tag is appended in the case of encryption, or verified in the case of decryption. The result is stored in the output buffer, starting at outputOffset inclusive.

If the output buffer is too small to hold the result, a ShortBufferException is thrown.

Upon finishing, this method resets this CipherSpi object to the state it was in when previously initialized via a call to engineInit. That is, the object is reset and available to encrypt or decrypt (depending on the operation mode that was specified in the call to engineInit) more data.

Note

if any exception is thrown, this CipherSpi object may need to be reset before it can be used again.

Parameters
input:byte[]

the input buffer

inputOffset:int

the offset in input where the input starts

inputLen:int

the input length

output:byte[]

the buffer for the result

outputOffset:int

the offset in output where the result is stored

Returns:int

the number of bytes stored in output

Exceptions
IllegalBlockSizeException:
if this cipher is a block cipher, no padding has been requested (only in encryption mode), and the total input length of the data processed by this cipher is not a multiple of block size; or if this encryption algorithm is unable to process the input data provided
BadPaddingException:
if this CipherSpi object is in decryption mode, and (un)padding has been requested, but the decrypted data is not bounded by the appropriate padding bytes
ShortBufferException:
if the given output buffer is too small to hold the result
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

Annotations
@Override
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

engineInitback to summary
protected void engineInit(int opmode, Key key, final AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException

Implements abstract javax.crypto.CipherSpi.engineInit.

Doc from javax.crypto.CipherSpi.engineInit.

Initializes this CipherSpi object with a key, a set of algorithm parameters, and a source of randomness.

The CipherSpi object is initialized for one of the following four operations: encryption, decryption, key wrapping or key unwrapping, depending on the value of opmode.

If this cipher requires any algorithm parameters and params is null, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption or key wrapping, and raise an InvalidAlgorithmParameterException if it is being initialized for decryption or key unwrapping. The generated parameters can be retrieved using engineGetParameters or engineGetIV (if the parameter is an IV).

If this cipher requires algorithm parameters that cannot be derived from the input parameters, and there are no reasonable provider-specific default values, initialization will necessarily fail.

If this cipher (including its feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them from random.

Note that when a CipherSpi object is initialized, it loses all previously-acquired state. In other words, initializing a CipherSpi object is equivalent to creating a new instance of that CipherSpi object and initializing it.

Parameters
opmode:int

the operation mode of this CipherSpi object (this is one of the following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE, or UNWRAP_MODE)

key:Key

the encryption key

params:AlgorithmParameterSpec

the algorithm parameters

random:SecureRandom

the source of randomness

Exceptions
InvalidKeyException:
if the given key is inappropriate for initializing this cipher
InvalidAlgorithmParameterException:
if the given algorithm parameters are inappropriate for this cipher, or if this cipher requires algorithm parameters and params is null
engineInitback to summary
protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException

Implements abstract javax.crypto.CipherSpi.engineInit.

Doc from javax.crypto.CipherSpi.engineInit.

Initializes this CipherSpi object with a key, a set of algorithm parameters, and a source of randomness.

The CipherSpi object is initialized for one of the following four operations: encryption, decryption, key wrapping or key unwrapping, depending on the value of opmode.

If this cipher requires any algorithm parameters and params is null, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption or key wrapping, and raise an InvalidAlgorithmParameterException if it is being initialized for decryption or key unwrapping. The generated parameters can be retrieved using engineGetParameters or engineGetIV (if the parameter is an IV).

If this cipher requires algorithm parameters that cannot be derived from the input parameters, and there are no reasonable provider-specific default values, initialization will necessarily fail.

If this cipher (including its feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them from random.

Note that when a CipherSpi object is initialized, it loses all previously-acquired state. In other words, initializing a CipherSpi object is equivalent to creating a new instance of that CipherSpi object and initializing it.

Parameters
opmode:int

the operation mode of this CipherSpi object (this is one of the following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE, or UNWRAP_MODE)

key:Key

the encryption key

params:AlgorithmParameters

the algorithm parameters

random:SecureRandom

the source of randomness

Exceptions
InvalidKeyException:
if the given key is inappropriate for initializing this cipher
InvalidAlgorithmParameterException:
if the given algorithm parameters are inappropriate for this cipher, or if this cipher requires algorithm parameters and params is null
engineInitback to summary
protected void engineInit(int opmode, Key key, SecureRandom random) throws InvalidKeyException

Implements abstract javax.crypto.CipherSpi.engineInit.

Doc from javax.crypto.CipherSpi.engineInit.

Initializes this CipherSpi object with a key and a source of randomness.

The CipherSpi object is initialized for one of the following four operations: encryption, decryption, key wrapping or key unwrapping, depending on the value of opmode.

If this cipher requires any algorithm parameters that cannot be derived from the given key, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption or key wrapping, and raise an InvalidKeyException if it is being initialized for decryption or key unwrapping. The generated parameters can be retrieved using engineGetParameters or engineGetIV (if the parameter is an IV).

If this cipher requires algorithm parameters that cannot be derived from the input parameters, and there are no reasonable provider-specific default values, initialization will necessarily fail.

If this cipher (including its feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them from random.

Note that when a CipherSpi object is initialized, it loses all previously-acquired state. In other words, initializing a CipherSpi object is equivalent to creating a new instance of that CipherSpi object and initializing it.

Parameters
opmode:int

the operation mode of this CipherSpi object (this is one of the following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE)

key:Key

the encryption key

random:SecureRandom

the source of randomness

Exceptions
InvalidKeyException:
if the given key is inappropriate for initializing this cipher, or requires algorithm parameters that cannot be determined from the given key
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, NoSuchAlgorithmException

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
NoSuchAlgorithmException:
if no installed providers can create keys of type wrappedKeyType for the wrappedKeyAlgorithm
engineUpdateback to summary
protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen)

Implements abstract javax.crypto.CipherSpi.engineUpdate.

Doc from javax.crypto.CipherSpi.engineUpdate.

Continues a multiple-part encryption or decryption operation (depending on how this CipherSpi object was initialized), processing another data part.

The first inputLen bytes in the input buffer, starting at inputOffset inclusive, are processed, and the result is stored in a new buffer.

Parameters
input:byte[]

the input buffer

inputOffset:int

the offset in input where the input starts

inputLen:int

the input length

Returns:byte[]

the new buffer with the result, or null if the cipher is a block cipher and the input data is too short to result in a new block

engineUpdateback to summary
protected int engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)

Implements abstract javax.crypto.CipherSpi.engineUpdate.

Doc from javax.crypto.CipherSpi.engineUpdate.

Continues a multiple-part encryption or decryption operation (depending on how this CipherSpi object was initialized), processing another data part.

The first inputLen bytes in the input buffer, starting at inputOffset inclusive, are processed, and the result is stored in the output buffer, starting at outputOffset inclusive.

If the output buffer is too small to hold the result, a ShortBufferException is thrown.

Parameters
input:byte[]

the input buffer

inputOffset:int

the offset in input where the input starts

inputLen:int

the input length

output:byte[]

the buffer for the result

outputOffset:int

the offset in output where the result is stored

Returns:int

the number of bytes stored in output

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)
getOutputback to summary
private byte[] getOutput() throws BadPaddingException, IllegalBlockSizeException
initFromSpecback to summary
private void initFromSpec(Set<Algorithm> currentAlgs, OAEPParameterSpec pSpec) throws NoSuchPaddingException
org.bouncycastle.jcajce.provider back to summary

private Class BaseSingleBlockCipher.BadBlockException

extends BadPaddingException
Class Inheritance

Field Summary

Modifier and TypeField and Description
private Throwable

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Throwable
getCause()

Overrides java.lang.Throwable.getCause.

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Field Detail

causeback to summary
private Throwable cause

Hides java.lang.Throwable.cause.

Constructor Detail

BadBlockExceptionback to summary
public BadBlockException(String msg, Throwable cause)

Method Detail

getCauseback to summary
public Throwable getCause()

Overrides java.lang.Throwable.getCause.

Doc from java.lang.Throwable.getCause.

Returns the cause of this throwable or null if the cause is nonexistent or unknown. (The cause is the throwable that caused this throwable to get thrown.)

This implementation returns the cause that was supplied via one of the constructors requiring a Throwable, or that was set after creation with the initCause(Throwable) method. While it is typically unnecessary to override this method, a subclass can override it to return a cause set by some other means. This is appropriate for a "legacy chained throwable" that predates the addition of chained exceptions to Throwable. Note that it is not necessary to override any of the PrintStackTrace methods, all of which invoke the getCause method to determine the cause of a throwable.

Returns:Throwable

the cause of this throwable or null if the cause is nonexistent or unknown.

org.bouncycastle.jcajce.provider back to summary

pack-priv Class BaseSingleBlockCipher.Builder

extends Object
Class Inheritance
  • java.lang.Object
  • org.bouncycastle.jcajce.provider.BaseSingleBlockCipher.Builder

Field Summary

Modifier and TypeField and Description
private final Algorithm[]
private Class<T>[]
private final Map<Algorithm, Parameters>
private FipsKeyWrapOperatorFactory<T extends Parameters, K extends Key>
private final BouncyCastleFipsProvider
private AsymmetricOperatorFactory<T extends Parameters>
private KeyWrapOperatorFactory<T extends Parameters, K extends Key>
private ParametersCreatorProvider<T extends Parameters>
private PrivateKeyConverter<T extends AsymmetricPrivateKey>
private boolean
private PublicKeyConverter<T extends AsymmetricPublicKey>
private boolean
private boolean

Constructor Summary

AccessConstructor and Description
pack-priv
Builder(BouncyCastleFipsProvider fipsProvider, Algorithm... algorithms)

pack-priv
Builder(BouncyCastleFipsProvider fipsProvider, Parameters... parameters)

Method Summary

Modifier and TypeMethod and Description
pack-priv BaseSingleBlockCipher
pack-priv BaseSingleBlockCipher.Builder
setPrivateKeyOnly(boolean privateKeyOnly)

pack-priv BaseSingleBlockCipher.Builder
setPublicKeyOnly(boolean publicKeyOnly)

pack-priv BaseSingleBlockCipher.Builder
setWrapModeOnly(boolean wrapModeOnly)

pack-priv BaseSingleBlockCipher.Builder
withFipsOperators(AsymmetricOperatorFactory<T extends Parameters> generalFactory, FipsKeyWrapOperatorFactory<T extends Parameters, K extends Key> fipsKeyWrapOperatorFactory)

pack-priv BaseSingleBlockCipher.Builder
withGeneralOperators(AsymmetricOperatorFactory<T extends Parameters> generalFactory, KeyWrapOperatorFactory<T extends Parameters, K extends Key> generalKeyWrapOperatorFactory)

pack-priv BaseSingleBlockCipher.Builder
withParameters(Class<T>[] availableSpecs)

pack-priv BaseSingleBlockCipher.Builder
pack-priv BaseSingleBlockCipher.Builder
pack-priv BaseSingleBlockCipher.Builder
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

algorithmsback to summary
private final Algorithm[] algorithms
availableSpecsback to summary
private Class<T>[] availableSpecs
baseParametersMapback to summary
private final Map<Algorithm, Parameters> baseParametersMap
fipsKeyWrapOperatorFactoryback to summary
private FipsKeyWrapOperatorFactory<T extends Parameters, K extends Key> fipsKeyWrapOperatorFactory
fipsProviderback to summary
private final BouncyCastleFipsProvider fipsProvider
generalFactoryback to summary
private AsymmetricOperatorFactory<T extends Parameters> generalFactory
generalKeyWrapOperatorFactoryback to summary
private KeyWrapOperatorFactory<T extends Parameters, K extends Key> generalKeyWrapOperatorFactory
parametersCreatorProviderback to summary
private ParametersCreatorProvider<T extends Parameters> parametersCreatorProvider
privateKeyConverterback to summary
private PrivateKeyConverter<T extends AsymmetricPrivateKey> privateKeyConverter
privateKeyOnlyback to summary
private boolean privateKeyOnly
publicKeyConverterback to summary
private PublicKeyConverter<T extends AsymmetricPublicKey> publicKeyConverter
publicKeyOnlyback to summary
private boolean publicKeyOnly
wrapModeOnlyback to summary
private boolean wrapModeOnly

Constructor Detail

Builderback to summary
pack-priv Builder(BouncyCastleFipsProvider fipsProvider, Algorithm... algorithms)
Builderback to summary
pack-priv Builder(BouncyCastleFipsProvider fipsProvider, Parameters... parameters)

Method Detail

buildback to summary
pack-priv BaseSingleBlockCipher build()
setPrivateKeyOnlyback to summary
pack-priv BaseSingleBlockCipher.Builder setPrivateKeyOnly(boolean privateKeyOnly)
setPublicKeyOnlyback to summary
pack-priv BaseSingleBlockCipher.Builder setPublicKeyOnly(boolean publicKeyOnly)
setWrapModeOnlyback to summary
pack-priv BaseSingleBlockCipher.Builder setWrapModeOnly(boolean wrapModeOnly)
withFipsOperatorsback to summary
pack-priv BaseSingleBlockCipher.Builder withFipsOperators(AsymmetricOperatorFactory<T extends Parameters> generalFactory, FipsKeyWrapOperatorFactory<T extends Parameters, K extends Key> fipsKeyWrapOperatorFactory)
withGeneralOperatorsback to summary
pack-priv BaseSingleBlockCipher.Builder withGeneralOperators(AsymmetricOperatorFactory<T extends Parameters> generalFactory, KeyWrapOperatorFactory<T extends Parameters, K extends Key> generalKeyWrapOperatorFactory)
withParametersback to summary
pack-priv BaseSingleBlockCipher.Builder withParameters(Class<T>[] availableSpecs)
withParametersCreatorProviderback to summary
pack-priv BaseSingleBlockCipher.Builder withParametersCreatorProvider(ParametersCreatorProvider<T extends Parameters> parametersCreatorProvider)
withPrivateKeyConverterback to summary
pack-priv BaseSingleBlockCipher.Builder withPrivateKeyConverter(PrivateKeyConverter<T extends AsymmetricPrivateKey> privateKeyConverter)
withPublicKeyConverterback to summary
pack-priv BaseSingleBlockCipher.Builder withPublicKeyConverter(PublicKeyConverter<T extends AsymmetricPublicKey> publicKeyConverter)