Class OAEPEncoding
- java.lang.Object
-
- org.gudy.bouncycastle.crypto.encodings.OAEPEncoding
-
- All Implemented Interfaces:
AsymmetricBlockCipher
public class OAEPEncoding extends java.lang.Object implements AsymmetricBlockCipher
Optimal Asymmetric Encryption Padding (OAEP) - see PKCS 1 V 2.
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]
defHash
private AsymmetricBlockCipher
engine
private boolean
forEncryption
private Digest
hash
private java.security.SecureRandom
random
-
Constructor Summary
Constructors Constructor Description OAEPEncoding(AsymmetricBlockCipher cipher)
OAEPEncoding(AsymmetricBlockCipher cipher, Digest hash)
OAEPEncoding(AsymmetricBlockCipher cipher, Digest hash, byte[] encodingParams)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
decodeBlock(byte[] in, int inOff, int inLen)
byte[]
encodeBlock(byte[] in, int inOff, int inLen)
int
getInputBlockSize()
returns the largest size an input block can be.int
getOutputBlockSize()
returns the maximum size of the block produced by this cipher.AsymmetricBlockCipher
getUnderlyingCipher()
void
init(boolean forEncryption, CipherParameters param)
initialise the cipher.private void
ItoOSP(int i, byte[] sp)
int to octet string.private byte[]
maskGeneratorFunction1(byte[] Z, int zOff, int zLen, int length)
mask generator function, as described in PKCS1v2.byte[]
processBlock(byte[] in, int inOff, int inLen)
process the block of len bytes stored in in from offset inOff.
-
-
-
Field Detail
-
defHash
private byte[] defHash
-
hash
private Digest hash
-
engine
private AsymmetricBlockCipher engine
-
random
private java.security.SecureRandom random
-
forEncryption
private boolean forEncryption
-
-
Constructor Detail
-
OAEPEncoding
public OAEPEncoding(AsymmetricBlockCipher cipher)
-
OAEPEncoding
public OAEPEncoding(AsymmetricBlockCipher cipher, Digest hash)
-
OAEPEncoding
public OAEPEncoding(AsymmetricBlockCipher cipher, Digest hash, byte[] encodingParams)
-
-
Method Detail
-
getUnderlyingCipher
public AsymmetricBlockCipher getUnderlyingCipher()
-
init
public void init(boolean forEncryption, CipherParameters param)
Description copied from interface:AsymmetricBlockCipher
initialise the cipher.- Specified by:
init
in interfaceAsymmetricBlockCipher
- Parameters:
forEncryption
- if true the cipher is initialised for encryption, if false for decryption.param
- the key and other data required by the cipher.
-
getInputBlockSize
public int getInputBlockSize()
Description copied from interface:AsymmetricBlockCipher
returns the largest size an input block can be.- Specified by:
getInputBlockSize
in interfaceAsymmetricBlockCipher
- Returns:
- maximum size for an input block.
-
getOutputBlockSize
public int getOutputBlockSize()
Description copied from interface:AsymmetricBlockCipher
returns the maximum size of the block produced by this cipher.- Specified by:
getOutputBlockSize
in interfaceAsymmetricBlockCipher
- Returns:
- maximum size of the output block produced by the cipher.
-
processBlock
public byte[] processBlock(byte[] in, int inOff, int inLen) throws InvalidCipherTextException
Description copied from interface:AsymmetricBlockCipher
process the block of len bytes stored in in from offset inOff.- Specified by:
processBlock
in interfaceAsymmetricBlockCipher
- Parameters:
in
- the input datainOff
- offset into the in array where the data startsinLen
- the length of the block to be processed.- Returns:
- the resulting byte array of the encryption/decryption process.
- Throws:
InvalidCipherTextException
- data decrypts improperly.
-
encodeBlock
public byte[] encodeBlock(byte[] in, int inOff, int inLen) throws InvalidCipherTextException
- Throws:
InvalidCipherTextException
-
decodeBlock
public byte[] decodeBlock(byte[] in, int inOff, int inLen) throws InvalidCipherTextException
- Throws:
InvalidCipherTextException
- if the decryypted block turns out to be badly formatted.
-
ItoOSP
private void ItoOSP(int i, byte[] sp)
int to octet string.
-
maskGeneratorFunction1
private byte[] maskGeneratorFunction1(byte[] Z, int zOff, int zLen, int length)
mask generator function, as described in PKCS1v2.
-
-