Skip to content

Comments

Compatibility with PHP5 < 5.4.0#2

Open
alasjo wants to merge 3 commits intophilios33:masterfrom
alasjo:master
Open

Compatibility with PHP5 < 5.4.0#2
alasjo wants to merge 3 commits intophilios33:masterfrom
alasjo:master

Conversation

@alasjo
Copy link

@alasjo alasjo commented Jul 21, 2015

I noticed when testing PHP AES File Encryption in PHP 5.3.1 that the creation of key failed (because hex2bin wasn't introduced until PHP 5.4.0). In the readme of this project it states compatibility with PHP5 so I set out to fulfill that statement.

I have added a function similar to the bin_* functions in the library that checks if hex2bin exists, otherwise using an alternative approach with pack from the PHP.net comment section.

Moreover, the mb_substr function seems to treat length of NULL as zero. I have added a check for NULL length and replace it with the mb_strlen of the string.

Tested and working in PHP 5.3.1.

alasjo added 2 commits July 20, 2015 21:49
Signed-off-by: Alasjo <alexander@alasjo.se>
Signed-off-by: Alasjo <alexander@alasjo.se>
@jonathangoncalves
Copy link

$len = strlen( **$str** ); for ( $i = 0; $i < $len; $i += 2 ) { $sbin .= pack( "H*", substr( $str, $i, 2 ) ); }

Why'd you use the "$str" variable? Shouldn't be "$string"?

@nbatteur
Copy link

yes Jonathan, it's true. And the good function is:
$len = strlen( $string ); for ( $i = 0; $i < $len; $i += 2 ) { $sbin .= chr( hexdec( $string{$i}.$string{( $i+1 )} ) ); }

Changed from `$str` to `$string`
@alasjo
Copy link
Author

alasjo commented Dec 29, 2016

I missed the typo of $string, commited the correct variable name. Somewhat late...

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

Successfully merging this pull request may close these issues.

3 participants