public function decryptCBC($data, $key, $iv) { // Decode the key and IV. $iv = base64_decode($iv); $key = base64_decode($key); // Decrypt the data. $data = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv); $padding = ord($data[strlen($data) - 1]); return substr($data, 0, -$padding); }
/** * Downloads a story's thumbnail. * * @param string $media_id * The media_id of the story. * @param string $key * The base64-encoded key of the story. * @param string $iv * The base64-encoded IV of the thumbnail. * * @return mixed * The thumbnail data or FALSE on failure. */ public function getStoryThumb($media_id, $key, $iv) { // Make sure we're logged in and have a valid access token. if (!$this->auth_token || !$this->username) { return FALSE; } // Retrieve encrypted story and decrypt. $blob = parent::get('/bq/story_thumbnail?story_id=' . $media_id); if (!empty($blob)) { return parent::decryptCBC($blob, $key, $iv); } return FALSE; }