Class AsymmetricHybridCipher
- java.lang.Object
- 
- javax.crypto.CipherSpi
- 
- org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExt
- 
- org.bouncycastle.pqc.jcajce.provider.util.AsymmetricHybridCipher
 
 
 
- 
- Direct Known Subclasses:
- McElieceFujisakiCipherSpi,- McElieceKobaraImaiCipherSpi,- McEliecePointchevalCipherSpi
 
 public abstract class AsymmetricHybridCipher extends CipherSpiExt The AsymmetricHybridCipher class extends CipherSpiExt. NOTE: Some Ciphers are using Padding. OneAndZeroesPadding is used as default padding. However padding can still be specified, but mode is not supported; if you try to instantiate the cipher with something else than "NONE" as mode, NoSuchAlgorithmException is thrown.
- 
- 
Field SummaryFields Modifier and Type Field Description protected java.security.spec.AlgorithmParameterSpecparamSpecParameterSpec used with this cipher- 
Fields inherited from class org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExtDECRYPT_MODE, ENCRYPT_MODE, opMode
 
- 
 - 
Constructor SummaryConstructors Constructor Description AsymmetricHybridCipher()
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract intdecryptOutputSize(int inLen)Compute the output size of an update() or doFinal() operation of a hybrid asymmetric cipher in decryption mode when given input of the specified length.abstract byte[]doFinal(byte[] input, int inOff, int inLen)Finish a multiple-part encryption or decryption operation (depending on how this cipher was initialized).intdoFinal(byte[] input, int inOff, int inLen, byte[] output, int outOff)Finish a multiple-part encryption or decryption operation (depending on how this cipher was initialized).protected abstract intencryptOutputSize(int inLen)Compute the output size of an update() or doFinal() operation of a hybrid asymmetric cipher in encryption mode when given input of the specified length.intgetBlockSize()byte[]getIV()Return the initialization vector.intgetOutputSize(int inLen)Return 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 inLen (in bytes).java.security.spec.AlgorithmParameterSpecgetParameters()Return the parameters used with this cipher.protected abstract voidinitCipherDecrypt(java.security.Key key, java.security.spec.AlgorithmParameterSpec params)Initialize the AsymmetricHybridCipher with a certain key for data encryption.protected abstract voidinitCipherEncrypt(java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom sr)Initialize the AsymmetricHybridCipher with a certain key for data encryption.voidinitDecrypt(java.security.Key key)Initialize the cipher for decryption by forwarding it to initDecrypt(Key, FlexiSecureRandom).voidinitDecrypt(java.security.Key key, java.security.spec.AlgorithmParameterSpec params)Initialize the cipher with a certain key for data decryption.voidinitEncrypt(java.security.Key key)Initialize the cipher for encryption by forwarding it toinitEncrypt(Key, AlgorithmParameterSpec, SecureRandom).voidinitEncrypt(java.security.Key key, java.security.SecureRandom random)Initialize this cipher for encryption by forwarding it toinitEncrypt(Key, AlgorithmParameterSpec, SecureRandom).voidinitEncrypt(java.security.Key key, java.security.spec.AlgorithmParameterSpec params)Initialize the cipher for encryption by forwarding it to initEncrypt(Key, FlexiSecureRandom, AlgorithmParameterSpec).voidinitEncrypt(java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random)Initialize the cipher with a certain key for data encryption.protected voidsetMode(java.lang.String modeName)Since asymmetric hybrid ciphers do not support modes, this method does nothing.protected voidsetPadding(java.lang.String paddingName)Since asymmetric hybrid ciphers do not support padding, this method does nothing.abstract byte[]update(byte[] input, int inOff, int inLen)Continue a multiple-part encryption or decryption operation (depending on how this cipher was initialized), processing another data part.intupdate(byte[] input, int inOff, int inLen, byte[] output, int outOff)Continue a multiple-part encryption or decryption operation (depending on how this cipher was initialized), processing another data part.- 
Methods inherited from class org.bouncycastle.pqc.jcajce.provider.util.CipherSpiExtdoFinal, doFinal, engineDoFinal, engineDoFinal, engineGetBlockSize, engineGetIV, engineGetKeySize, engineGetOutputSize, engineGetParameters, engineInit, engineInit, engineInit, engineSetMode, engineSetPadding, engineUpdate, engineUpdate, getKeySize, getName, update
 
- 
 
- 
- 
- 
Method Detail- 
setModeprotected final void setMode(java.lang.String modeName) Since asymmetric hybrid ciphers do not support modes, this method does nothing.- Specified by:
- setModein class- CipherSpiExt
- Parameters:
- modeName- the cipher mode (unused)
 
 - 
setPaddingprotected final void setPadding(java.lang.String paddingName) Since asymmetric hybrid ciphers do not support padding, this method does nothing.- Specified by:
- setPaddingin class- CipherSpiExt
- Parameters:
- paddingName- the name of the padding scheme (not used)
 
 - 
getIVpublic final byte[] getIV() Description copied from class:CipherSpiExtReturn the initialization vector. This is useful in the context of password-based encryption or decryption, where the IV is derived from a user-provided passphrase.- Specified by:
- getIVin class- CipherSpiExt
- Returns:
- null since no initialization vector is used.
 
 - 
getBlockSizepublic final int getBlockSize() - Specified by:
- getBlockSizein class- CipherSpiExt
- Returns:
- 0 since the implementing algorithms are not block ciphers
 
 - 
getParameterspublic final java.security.spec.AlgorithmParameterSpec getParameters() Return the parameters used with this cipher.The returned parameters may be the same that were used to initialize this cipher, or may contain the default set of parameters or a set of randomly generated parameters used by the underlying cipher implementation (provided that the underlying cipher implementation uses a default set of parameters or creates new parameters if it needs parameters but was not initialized with any). - Specified by:
- getParametersin class- CipherSpiExt
- Returns:
- the parameters used with this cipher, or null if this cipher does not use any parameters.
 
 - 
getOutputSizepublic final int getOutputSize(int inLen) Return 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 inLen (in bytes). This call takes into account any unprocessed (buffered) data from a previous update call, and padding. The actual output length of the next update() or doFinal() call may be smaller than the length returned by this method.- Specified by:
- getOutputSizein class- CipherSpiExt
- Parameters:
- inLen- the length of the input
- Returns:
- the length of the output of the next update() or doFinal() call
 
 - 
initEncryptpublic final void initEncrypt(java.security.Key key) throws java.security.InvalidKeyExceptionInitialize the cipher for encryption by forwarding it toinitEncrypt(Key, AlgorithmParameterSpec, SecureRandom).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, and raise an InvalidKeyException if it is being initialized for decryption. The generated parameters can be retrieved using getParameters().- Parameters:
- key- the encryption key
- Throws:
- java.security.InvalidKeyException- if the given key is inappropriate for initializing this cipher.
- java.security.InvalidParameterException- if this cipher needs algorithm parameters for initialization and cannot generate parameters itself.
 
 - 
initEncryptpublic final void initEncrypt(java.security.Key key, java.security.SecureRandom random) throws java.security.InvalidKeyExceptionInitialize this cipher for encryption by forwarding it toinitEncrypt(Key, AlgorithmParameterSpec, SecureRandom).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, and raise an InvalidKeyException if it is being initialized for decryption. The generated parameters can be retrieved using getParameters().- Parameters:
- key- the encryption key
- random- the source of randomness
- Throws:
- java.security.InvalidKeyException- if the given key is inappropriate for initializing this cipher.
- java.security.InvalidParameterException- if this cipher needs algorithm parameters for initialization and cannot generate parameters itself.
 
 - 
initEncryptpublic final void initEncrypt(java.security.Key key, java.security.spec.AlgorithmParameterSpec params) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterExceptionInitialize the cipher for encryption by forwarding it to initEncrypt(Key, FlexiSecureRandom, AlgorithmParameterSpec).- Parameters:
- key- the encryption key
- params- the algorithm parameters
- Throws:
- java.security.InvalidKeyException- if the given key is inappropriate for initializing this cipher.
- java.security.InvalidAlgorithmParameterException- if the given algorithm parameters are inappropriate for this cipher, or if this cipher is initialized with null parameters and cannot generate parameters itself.
 
 - 
initEncryptpublic final void initEncrypt(java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterExceptionInitialize the cipher with a certain key for data encryption.If this cipher requires any random bytes (e.g., for parameter generation), it will get them from random. Note that when a Cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher and initializing it. - Specified by:
- initEncryptin class- CipherSpiExt
- Parameters:
- key- the encryption key
- random- the source of randomness
- params- the algorithm parameters
- Throws:
- java.security.InvalidKeyException- if the given key is inappropriate for initializing this cipher
- java.security.InvalidAlgorithmParameterException- if the given algorithm parameters are inappropriate for this cipher, or if this cipher is initialized with null parameters and cannot generate parameters itself.
 
 - 
initDecryptpublic final void initDecrypt(java.security.Key key) throws java.security.InvalidKeyExceptionInitialize the cipher for decryption by forwarding it to initDecrypt(Key, FlexiSecureRandom).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, and raise an InvalidKeyException if it is being initialized for decryption. The generated parameters can be retrieved using getParameters().- Parameters:
- key- the decryption key
- Throws:
- java.security.InvalidKeyException- if the given key is inappropriate for initializing this cipher.
 
 - 
initDecryptpublic final void initDecrypt(java.security.Key key, java.security.spec.AlgorithmParameterSpec params) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterExceptionInitialize the cipher with a certain key for data decryption.If this cipher requires any random bytes (e.g., for parameter generation), it will get them from random. Note that when a Cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher and initializing it - Specified by:
- initDecryptin class- CipherSpiExt
- Parameters:
- key- the decryption key
- params- the algorithm parameters
- Throws:
- java.security.InvalidKeyException- if the given key is inappropriate for initializing this cipher
- java.security.InvalidAlgorithmParameterException- if the given algorithm parameters are inappropriate for this cipher, or if this cipher is initialized with null parameters and cannot generate parameters itself.
 
 - 
updatepublic abstract byte[] update(byte[] input, int inOff, int inLen)Continue a multiple-part encryption or decryption operation (depending on how this cipher was initialized), processing another data part.- Specified by:
- updatein class- CipherSpiExt
- Parameters:
- input- the input buffer
- inOff- the offset where the input starts
- inLen- the input length
- Returns:
- a new buffer with the result (maybe an empty byte array)
 
 - 
updatepublic final int update(byte[] input, int inOff, int inLen, byte[] output, int outOff) throws javax.crypto.ShortBufferExceptionContinue a multiple-part encryption or decryption operation (depending on how this cipher was initialized), processing another data part.- Specified by:
- updatein class- CipherSpiExt
- Parameters:
- input- the input buffer
- inOff- the offset where the input starts
- inLen- the input length
- output- the output buffer
- outOff- the offset where the result is stored
- Returns:
- the length of the output
- Throws:
- javax.crypto.ShortBufferException- if the output buffer is too small to hold the result.
 
 - 
doFinalpublic abstract byte[] doFinal(byte[] input, int inOff, int inLen) throws javax.crypto.BadPaddingExceptionFinish a multiple-part encryption or decryption operation (depending on how this cipher was initialized).- Specified by:
- doFinalin class- CipherSpiExt
- Parameters:
- input- the input buffer
- inOff- the offset where the input starts
- inLen- the input length
- Returns:
- a new buffer with the result
- Throws:
- javax.crypto.BadPaddingException- if the ciphertext is invalid.
 
 - 
doFinalpublic final int doFinal(byte[] input, int inOff, int inLen, byte[] output, int outOff) throws javax.crypto.ShortBufferException, javax.crypto.BadPaddingExceptionFinish a multiple-part encryption or decryption operation (depending on how this cipher was initialized).- Specified by:
- doFinalin class- CipherSpiExt
- Parameters:
- input- the input buffer
- inOff- the offset where the input starts
- inLen- the input length
- output- the buffer for the result
- outOff- the offset where the result is stored
- Returns:
- the output length
- Throws:
- javax.crypto.ShortBufferException- if the output buffer is too small to hold the result.
- javax.crypto.BadPaddingException- if the ciphertext is invalid.
 
 - 
encryptOutputSizeprotected abstract int encryptOutputSize(int inLen) Compute the output size of an update() or doFinal() operation of a hybrid asymmetric cipher in encryption mode when given input of the specified length.- Parameters:
- inLen- the length of the input
- Returns:
- the output size
 
 - 
decryptOutputSizeprotected abstract int decryptOutputSize(int inLen) Compute the output size of an update() or doFinal() operation of a hybrid asymmetric cipher in decryption mode when given input of the specified length.- Parameters:
- inLen- the length of the input
- Returns:
- the output size
 
 - 
initCipherEncryptprotected abstract void initCipherEncrypt(java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom sr) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterExceptionInitialize the AsymmetricHybridCipher with a certain key for data encryption.- Parameters:
- key- the key which has to be used to encrypt data
- params- the algorithm parameters
- sr- the source of randomness
- Throws:
- java.security.InvalidKeyException- if the given key is inappropriate for initializing this cipher.
- java.security.InvalidAlgorithmParameterException- if the given parameters are inappropriate for initializing this cipher.
 
 - 
initCipherDecryptprotected abstract void initCipherDecrypt(java.security.Key key, java.security.spec.AlgorithmParameterSpec params) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterExceptionInitialize the AsymmetricHybridCipher with a certain key for data encryption.- Parameters:
- key- the key which has to be used to decrypt data
- params- the algorithm parameters
- Throws:
- java.security.InvalidKeyException- if the given key is inappropriate for initializing this cipher
- java.security.InvalidAlgorithmParameterException- if the given parameters are inappropriate for initializing this cipher.
 
 
- 
 
-