Skip to content

Commit 3bb2088

Browse files
author
Lucas Dohring
committed
Merge pull request #1 from singron/master
PKCS5 Padding
2 parents f082ecf + 76e6aeb commit 3bb2088

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

snaphax.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,22 @@ function isValidBlobHeader($header) {
192192
else
193193
return false;
194194
}
195+
196+
function pkcs5pad($data) {
197+
// Block size is 16 bytes
198+
$needed_padding = 16 - strlen($data) % 16;
199+
if ($needed_padding == 0) {
200+
$needed_padding = 16;
201+
}
202+
return $data . str_repeat(chr($needed_padding), $needed_padding);
203+
}
195204

196205
function decrypt($data) {
197-
return mcrypt_decrypt('rijndael-128', $this->options['blob_enc_key'], $data, 'ecb');
206+
return mcrypt_decrypt('rijndael-128', $this->options['blob_enc_key'], pkcs5pad($data), 'ecb');
198207
}
199208

200209
function encrypt($data) {
201-
return mcrypt_encrypt('rijndael-128', $this->options['blob_enc_key'], $data, 'ecb');
210+
return mcrypt_encrypt('rijndael-128', $this->options['blob_enc_key'], pkcs5pad($data), 'ecb');
202211
}
203212

204213
public function postCall($endpoint, $post_data, $param1, $param2, $json=1, $headers=false) {

0 commit comments

Comments
 (0)