dropbox-php-sdk icon indicating copy to clipboard operation
dropbox-php-sdk copied to clipboard

Function mcrypt_create_iv() is deprecated

Open xiebruce opened this issue 5 years ago • 0 comments

Deprecated: Function mcrypt_create_iv() is deprecated in /Users/bruce/www/personal/PicUploader/vendor/kunalvarma05/dropbox-php-sdk/src/Dropbox/Security/McryptRandomStringGenerator.php on line 47

this issue also mentioned almost 3 years ago: https://github.com/kunalvarma05/dropbox-php-sdk/issues/29, but didn't fix yet.

I've fixed this issue, there is a function generateString($length) in file vendor/kunalvarma05/dropbox-php-sdk/src/Dropbox/Security/McryptRandomStringGenerator.php:

Before fix:

public function generateString($length)
    {
        //Create Binary String
        $binaryString = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
		
        //Unable to create binary string
        if ($binaryString === false) {
            throw new DropboxClientException(
                static::ERROR_MESSAGE .
                'mcrypt_create_iv() returned an error.'
                );
        }

        //Convert binary to hex
        return $this->binToHex($binaryString, $length);
    }

After fixed:

public function generateString($length)
    {
        //Create Binary String
        // $binaryString = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
        $binaryString = random_bytes($length);
		
        //Unable to create binary string
        if ($binaryString === false) {
            throw new DropboxClientException(
                static::ERROR_MESSAGE .
                'mcrypt_create_iv() returned an error.'
                );
        }

        //Convert binary to hex
        return $this->binToHex($binaryString, $length);
    }

All you need to do is to change

$binaryString = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);

to

$binaryString = random_bytes($length);

xiebruce avatar Nov 01 '19 05:11 xiebruce