PHP code example of fdevs / padding

1. Go to this page and download the library: Download fdevs/padding library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fdevs / padding example snippets



use FDevs\Padding\Pkcs7;
use FDevs\Padding\NoPadding;

$padding = new Pkcs7();

$data = '';//your data without padding
$blockSize = 32;//your block size default 32
$paddingData = $padding->pad($data,$blockSize);

echo $padding->unpad($paddingData, $blockSize); 


use FDevs\Padding\Pkcs7;

$padding = new Pkcs7();

$data = '';//your data without padding
$key = '';//your secret keys
$blockSize = mcrypt_get_block_size('des', 'ecb');

echo mcrypt_encrypt(MCRYPT_DES, $key, $padding->pad($data,$blockSize), MCRYPT_MODE_ECB);

$str = '';//crypto data
$paddingData = $str = mcrypt_decrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB);

echo $padding->unpad($paddingData, $blockSize);