Skip to content

Compatibility with PHP5 < 5.4.0 #2

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion AESCryptFileLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ private function getBinaryExtensionData($ext_data)
private function createKeyUsingIVAndPassphrase($iv, $passphrase)
{
//Start with the IV padded to 32 bytes
$aes_key = str_pad($iv, 32, hex2bin("00"));
$aes_key = str_pad($iv, 32, self::hex2bin("00"));
$iterations = 8192;
for($i=0; $i<$iterations; $i++)
{
Expand Down Expand Up @@ -609,11 +609,32 @@ public static function bin_strpos($haystack, $needle, $offset = 0) {

public static function bin_substr($string, $start, $length = NULL) {
if (function_exists('mb_substr')) {
if (is_null($length)) {
//Passing $length=NULL to mb_substring will treat it as 0
//http://php.net/manual/en/function.mb-substr.php#77515
$length = mb_strlen($string, '8bit');
}
return mb_substr($string, $start, $length, '8bit');
} else {
return substr($string, $start, $length);
}
}

//hex2bin wasn't introduced until PHP 5.4.0. If not present, use an alternative
//written by jannik: http://php.net/manual/en/function.hex2bin.php#113057
public static function hex2bin($string) {
if (function_exists('hex2bin')) {
return hex2bin($string);
} else {
$sbin = "";
$len = strlen( $string );
for ( $i = 0; $i < $len; $i += 2 ) {
$sbin .= pack( "H*", substr( $string, $i, 2 ) );
}

return $sbin;
}
}

}

Expand Down