Top Description Fields Constructors Methods
org.bouncycastle.crypto.internal.encodings

public Class PKCS1Encoding

extends Object
implements AsymmetricBlockCipher
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.internal.AsymmetricBlockCipher
Imports
java.security.SecureRandom, org.bouncycastle.crypto.CryptoServicesRegistrar, org.bouncycastle.crypto.internal.AsymmetricBlockCipher, .CipherParameters, .InvalidCipherTextException, org.bouncycastle.crypto.internal.params.AsymmetricKeyParameter, .ParametersWithRandom, org.bouncycastle.util.Arrays, .Properties

this does your basic PKCS 1 v1.5 padding - whether or not you should be using this depends on your application - see PKCS1 Version 2 for details.

Field Summary

Modifier and TypeField and Description
private byte[]
private AsymmetricBlockCipher
private boolean
private boolean
private static final int
public static final String
NOT_STRICT_LENGTH_ENABLED_PROPERTY

some providers fail to include the leading zero in PKCS1 encoded blocks.

private SecureRandom
private boolean

Constructor Summary

AccessConstructor and Description
public
PKCS1Encoding(AsymmetricBlockCipher cipher)

Basic constructor.

Method Summary

Modifier and TypeMethod and Description
private byte[]
decodeBlock(byte[] in, int inOff, int inLen)

private byte[]
encodeBlock(byte[] in, int inOff, int inLen)

private int
findStart(byte type, byte[] block)

public int
getInputBlockSize()

Implements org.bouncycastle.crypto.internal.AsymmetricBlockCipher.getInputBlockSize.

returns the largest size an input block can be.
public int
getOutputBlockSize()

Implements org.bouncycastle.crypto.internal.AsymmetricBlockCipher.getOutputBlockSize.

returns the maximum size of the block produced by this cipher.
public AsymmetricBlockCipher
public void
init(boolean
if true the cipher is initialised for encryption, if false for decryption.
forEncryption
,
CipherParameters
the key and other data required by the cipher.
param
)

Implements org.bouncycastle.crypto.internal.AsymmetricBlockCipher.init.

initialise the cipher.
public byte[]
processBlock(byte[]
the input data
in
,
int
offset into the in array where the data starts
inOff
,
int
the length of the block to be processed.
inLen
)

Implements org.bouncycastle.crypto.internal.AsymmetricBlockCipher.processBlock.

process the block of len bytes stored in in from offset inOff.
private boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dudBlockback to summary
private byte[] dudBlock
engineback to summary
private AsymmetricBlockCipher engine
forEncryptionback to summary
private boolean forEncryption
forPrivateKeyback to summary
private boolean forPrivateKey
HEADER_LENGTHback to summary
private static final int HEADER_LENGTH
NOT_STRICT_LENGTH_ENABLED_PROPERTYback to summary
public static final String NOT_STRICT_LENGTH_ENABLED_PROPERTY

some providers fail to include the leading zero in PKCS1 encoded blocks. If you need to work with one of these set the system property org.bouncycastle.pkcs1.strict to false.

The system property is checked during construction of the encoding object, it is set to true by default.

randomback to summary
private SecureRandom random
useStrictLengthback to summary
private boolean useStrictLength

Constructor Detail

PKCS1Encodingback to summary
public PKCS1Encoding(AsymmetricBlockCipher cipher)

Basic constructor.

Method Detail

decodeBlockback to summary
private byte[] decodeBlock(byte[] in, int inOff, int inLen) throws InvalidCipherTextException
Exceptions
InvalidCipherTextException:
if the decrypted block is not in PKCS1 format.
encodeBlockback to summary
private byte[] encodeBlock(byte[] in, int inOff, int inLen) throws InvalidCipherTextException
findStartback to summary
private int findStart(byte type, byte[] block) throws InvalidCipherTextException
getInputBlockSizeback to summary
public int getInputBlockSize()

Implements org.bouncycastle.crypto.internal.AsymmetricBlockCipher.getInputBlockSize.

Doc from org.bouncycastle.crypto.internal.AsymmetricBlockCipher.getInputBlockSize.

returns the largest size an input block can be.

Returns:int

maximum size for an input block.

getOutputBlockSizeback to summary
public int getOutputBlockSize()

Implements org.bouncycastle.crypto.internal.AsymmetricBlockCipher.getOutputBlockSize.

Doc from org.bouncycastle.crypto.internal.AsymmetricBlockCipher.getOutputBlockSize.

returns the maximum size of the block produced by this cipher.

Returns:int

maximum size of the output block produced by the cipher.

getUnderlyingCipherback to summary
public AsymmetricBlockCipher getUnderlyingCipher()
initback to summary
public void init(boolean forEncryption, CipherParameters param)

Implements org.bouncycastle.crypto.internal.AsymmetricBlockCipher.init.

Doc from org.bouncycastle.crypto.internal.AsymmetricBlockCipher.init.

initialise the cipher.

Parameters
forEncryption:boolean

if true the cipher is initialised for encryption, if false for decryption.

param:CipherParameters

the key and other data required by the cipher.

processBlockback to summary
public byte[] processBlock(byte[] in, int inOff, int inLen) throws InvalidCipherTextException

Implements org.bouncycastle.crypto.internal.AsymmetricBlockCipher.processBlock.

Doc from org.bouncycastle.crypto.internal.AsymmetricBlockCipher.processBlock.

process the block of len bytes stored in in from offset inOff.

Parameters
in:byte[]

the input data

inOff:int

offset into the in array where the data starts

inLen:int

the length of the block to be processed.

Returns:byte[]

the resulting byte array of the encryption/decryption process.

Exceptions
InvalidCipherTextException:
data decrypts improperly.
useStrictback to summary
private boolean useStrict()