Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function mcrypt_create_iv() is deprecated #154

Open
xiebruce opened this issue Nov 1, 2019 · 0 comments
Open

Function mcrypt_create_iv() is deprecated #154

xiebruce opened this issue Nov 1, 2019 · 0 comments

Comments

@xiebruce
Copy link

xiebruce commented Nov 1, 2019

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: #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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant