From 052e5bd1bef9bc5eef3fdd3c8466c1d83b7a2165 Mon Sep 17 00:00:00 2001 From: Daniele Cruciani Date: Tue, 17 Nov 2015 13:44:42 +0100 Subject: [PATCH] adding an extra block if block size in padding PKCS padding specify to add an extra block (otherwise when decrypting the removed extra (-$padding) is randomly given from the ascii code of the last character) --- security.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/security.php b/security.php index c2f266a..07b87db 100644 --- a/security.php +++ b/security.php @@ -15,6 +15,10 @@ public static function encrypt($input, $key) { private static function pkcs5_pad ($text, $blocksize) { $pad = $blocksize - (strlen($text) % $blocksize); + if($pad == 0) { + // if text size is multiple of blocksize, then is added an extra block + $pad = $blocksize; + } return $text . str_repeat(chr($pad), $pad); }