Package org.bouncycastle.openpgp
Class PGPPadding
- java.lang.Object
-
- org.bouncycastle.openpgp.PGPPadding
-
public class PGPPadding extends java.lang.Object
The PGPPadding contains random data, and can be used to defend against traffic analysis on version 2 SEIPD messages and Transferable Public Keys.Such a padding packet MUST be ignored when received.
-
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_PADDING_LEN
Maximum random padding length.static int
MIN_PADDING_LEN
Minimum random padding length in octets.
-
Constructor Summary
Constructors Constructor Description PGPPadding()
Generate a new, randomPGPPadding
object.PGPPadding(int len)
Generate a new, randomPGPPadding
object.PGPPadding(int len, java.security.SecureRandom random)
Generate a new, randomPGPPadding
object.PGPPadding(java.security.SecureRandom random)
Generate a new, randomPGPPadding
object.PGPPadding(BCPGInputStream in)
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
encode(java.io.OutputStream outStream)
byte[]
getEncoded()
byte[]
getEncoded(PacketFormat format)
byte[]
getPadding()
Return the padding octets as a byte array.
-
-
-
Field Detail
-
MIN_PADDING_LEN
public static final int MIN_PADDING_LEN
Minimum random padding length in octets. Chosen totally arbitrarily.- See Also:
- Constant Field Values
-
MAX_PADDING_LEN
public static final int MAX_PADDING_LEN
Maximum random padding length. Chosen somewhat arbitrarily, as SSH also uses max 255 bytes for random padding.
-
-
Constructor Detail
-
PGPPadding
public PGPPadding(BCPGInputStream in) throws java.io.IOException
Default constructor.- Parameters:
in
- packet input stream- Throws:
java.io.IOException
-
PGPPadding
public PGPPadding()
Generate a new, randomPGPPadding
object. The padding consists of n random bytes, where n is a number between (inclusive)MIN_PADDING_LEN
andMAX_PADDING_LEN
.
-
PGPPadding
public PGPPadding(java.security.SecureRandom random)
Generate a new, randomPGPPadding
object. The padding consists of n random bytes, where n is a number between (inclusive)MIN_PADDING_LEN
andMAX_PADDING_LEN
.- Parameters:
random
- random number generator instance
-
PGPPadding
public PGPPadding(int len)
Generate a new, randomPGPPadding
object. The padding consists of len random bytes.
-
PGPPadding
public PGPPadding(int len, java.security.SecureRandom random)
Generate a new, randomPGPPadding
object. The padding consists of len random bytes.- Parameters:
len
- number of random octetsrandom
- random number generator instance
-
-
Method Detail
-
getPadding
public byte[] getPadding()
Return the padding octets as a byte array.- Returns:
- padding octets
-
encode
public void encode(java.io.OutputStream outStream) throws java.io.IOException
- Throws:
java.io.IOException
-
getEncoded
public byte[] getEncoded() throws java.io.IOException
- Throws:
java.io.IOException
-
getEncoded
public byte[] getEncoded(PacketFormat format) throws java.io.IOException
- Throws:
java.io.IOException
-
-