PKCS1Encoding (Bouncy Castle Library 1.85 API Specification)
Date: 2026-07-12

org.bouncycastle.crypto.encodings

## Class PKCS1Encoding

- java.lang.Object
- - org.bouncycastle.crypto.encodings.PKCS1Encoding

- All Implemented Interfaces:
    AsymmetricBlockCipher

      public class PKCS1Encoding
      extends java.lang.Object
      implements AsymmetricBlockCipher

  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

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `NOT_STRICT_LENGTH_ENABLED_PROPERTY` some providers fail to include the leading zero in PKCS1 encoded blocks.
    `static java.lang.String` | `STRICT_LENGTH_ENABLED_PROPERTY` Deprecated. use NOT_STRICT_LENGTH_ENABLED_PROPERTY

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PKCS1Encoding(AsymmetricBlockCipher cipher)` Basic constructor.
    `PKCS1Encoding(AsymmetricBlockCipher cipher, byte[] fallback)` Constructor for decryption with a fixed plaintext length and a fallback value that is returned, if the padding is incorrect.
    `PKCS1Encoding(AsymmetricBlockCipher cipher, int pLen)` Constructor for decryption with a fixed plaintext length.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `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.
    `byte[]` | `processBlock(byte[] in, int inOff, int inLen)` process the block of len bytes stored in in from offset inOff.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### STRICT_LENGTH_ENABLED_PROPERTY

          public static final java.lang.String STRICT_LENGTH_ENABLED_PROPERTY

      Deprecated. use NOT_STRICT_LENGTH_ENABLED_PROPERTY
      See Also:
        Constant Field Values

    - #### NOT_STRICT_LENGTH_ENABLED_PROPERTY

          public static final java.lang.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.not_strict to true.

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

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### PKCS1Encoding

          public PKCS1Encoding(AsymmetricBlockCipher cipher)

      Basic constructor.
      Parameters:
        `cipher` -

    - #### PKCS1Encoding

          public PKCS1Encoding(AsymmetricBlockCipher cipher,
                               int pLen)

      Constructor for decryption with a fixed plaintext length.
      Parameters:
        `cipher` - The cipher to use for cryptographic operation.
        `pLen` - Length of the expected plaintext.

    - #### PKCS1Encoding

          public PKCS1Encoding(AsymmetricBlockCipher cipher,
                               byte[] fallback)

      Constructor for decryption with a fixed plaintext length and a fallback value that is returned, if the padding is incorrect.
      Parameters:
        `cipher` - The cipher to use for cryptographic operation.
        `fallback` - The fallback value, we don't do an arraycopy here.

  - ### 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 interface `AsymmetricBlockCipher`
      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 interface `AsymmetricBlockCipher`
      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 interface `AsymmetricBlockCipher`
      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 interface `AsymmetricBlockCipher`
      Parameters:
        `in` - the input data
        `inOff` - offset into the in array where the data starts
        `inLen` - the length of the block to be processed.
      Returns:
        the resulting byte array of the encryption/decryption process.
      Throws:
        `InvalidCipherTextException` - data decrypts improperly.