Package Cryptodome :: Package Util :: Module Padding

Module Padding

Functions to manage padding

This module provides minimal support for adding and removing standard padding from data.

Functions
 
pad(data_to_pad, block_size, style='pkcs7')
Apply standard padding.
 
unpad(padded_data, block_size, style='pkcs7')
Remove standard padding.
Function Details

pad(data_to_pad, block_size, style='pkcs7')

 
Apply standard padding.
Parameters:
  • data_to_pad (byte string) - The data that needs to be padded.
  • block_size (integer) - The block boundary to use for padding. The output length is guaranteed to be a multiple of block_size.
  • style (string) - Padding algorithm. It can be 'pkcs7' (default), 'iso7816' or 'x923'.
Returns:
The original data with the appropriate padding added at the end.

unpad(padded_data, block_size, style='pkcs7')

 
Remove standard padding.
Parameters:
  • padded_data (byte string) - A piece of data with padding that needs to be stripped.
  • block_size (integer) - The block boundary to use for padding. The input length must be a multiple of block_size.
  • style (string) - Padding algorithm. It can be 'pkcs7' (default), 'iso7816' or 'x923'.
Returns:
Data without padding.
Raises:
  • ValueError - if the padding is incorrect.