SnapchatAgent::decryptCBC PHP Method

decryptCBC() public method

Decrypts blob data for stories.
public decryptCBC ( data $data, string $key, string $iv ) : data
$data data The data to decrypt.
$key string The base64-encoded key.
$iv string $iv The base64-encoded IV.
return data The decrypted data.
    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);
    }

Usage Example

コード例 #1
0
ファイル: snapchat.php プロジェクト: krew25/SC-API
 /**
  * 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;
 }