Skip to content

Commit

Permalink
Merge pull request #1 from singron/master
Browse files Browse the repository at this point in the history
PKCS5 Padding
  • Loading branch information
Lucas Dohring committed Feb 10, 2013
2 parents f082ecf + 76e6aeb commit 3bb2088
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions snaphax.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,22 @@ function isValidBlobHeader($header) {
else
return false;
}

function pkcs5pad($data) {
// Block size is 16 bytes
$needed_padding = 16 - strlen($data) % 16;
if ($needed_padding == 0) {
$needed_padding = 16;
}
return $data . str_repeat(chr($needed_padding), $needed_padding);
}

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

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

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

0 comments on commit 3bb2088

Please sign in to comment.