**Cryptography Tutorials - Herong's Tutorial Examples** - Version 5.31, by Dr. Herong Yang

What Is PKCS5Padding?

This section describes what is PKCS5Padding - a schema to pad cleartext to be multiples of 8-byte blocks.

As you can see from previous tutorials, DES algorithm requires that the input data to be 8-byte blocks. If you want to encrypt a text message that is not multiples of 8-byte blocks, the text message must be padded with additional bytes to make the text message to be multiples of 8-byte blocks.

PKCS5Padding is a padding scheme described in: RSA Laboratories, "PKCS #5: Password-Based Encryption Standard," version 1.5, November 1993.

PKCS5Padding schema is actually very simple. It follows the following rules:

- The number of bytes to be padded equals to "8 - numberOfBytes(clearText) mod 8". So 1 to 8 bytes will be padded to the clear text data depending on the length of the clear text data.
- All padded bytes have the same value - the number of bytes padded.

PKCS5Padding schema can also be explained with the diagram below, if M is the original clear text and PM is the padded clear text:

If numberOfBytes(clearText) mod 8 == 7, PM = M + 0x01 If numberOfBytes(clearText) mod 8 == 6, PM = M + 0x0202 If numberOfBytes(clearText) mod 8 == 5, PM = M + 0x030303 ... If numberOfBytes(clearText) mod 8 == 0, PM = M + 0x0808080808080808

Table of Contents

Introduction to AES (Advanced Encryption Standard)

DES Algorithm - Illustrated with Java Programs

DES Algorithm Java Implementation

►DES Algorithm - Java Implementation in JDK JCE

DES Java Implementation in JDK by Sun

Steps of Using DES Algorithm in JDK JCE

Testing DES Algorithm in JDK JCE

JceSunDesPaddingTest.java - JCE DES Padding Test

DES Encryption Operation Modes

PHP Implementation of DES - mcrypt

Blowfish - 8-Byte Block Cipher

Secret Key Generation and Management

Cipher - Secret Key Encryption and Decryption

RSA Implementation using java.math.BigInteger Class

Introduction of DSA (Digital Signature Algorithm)

Java Default Implementation of DSA

Private key and Public Key Pair Generation

PKCS#8/X.509 Private/Public Encoding Standards

Cipher - Public Key Encryption and Decryption

OpenSSL Introduction and Installation

OpenSSL Generating and Managing RSA Keys

OpenSSL Generating and Signing CSR

OpenSSL Validating Certificate Path

"keytool" and "keystore" from JDK

"OpenSSL" Signing CSR Generated by "keytool"

Migrating Keys from "keystore" to "OpenSSL" Key Files

Certificate X.509 Standard and DER/PEM Formats

Migrating Keys from "OpenSSL" Key Files to "keystore"

Using Certificates in IE (Internet Explorer)