Skip to content

Commit

Permalink
Use the PKCS5 padding method used by the app
Browse files Browse the repository at this point in the history
  • Loading branch information
singron committed Feb 10, 2013
1 parent f082ecf commit 76e6aeb
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 76e6aeb

Please sign in to comment.