Browse Source

base64_encode() encrypted binary data

pull/580/head
Sebastian Meyer 2 months ago
parent
commit
56b69fc303
1 changed files with 6 additions and 5 deletions
  1. +6
    -5
      Classes/Common/Helper.php

+ 6
- 5
Classes/Common/Helper.php View File

@@ -185,11 +185,12 @@ class Helper
return false;
}
// Split initialisation vector and encrypted data.
$iv = substr($encrypted, 0, openssl_cipher_iv_length(self::$cipherAlgorithm));
$data = substr($encrypted, openssl_cipher_iv_length(self::$cipherAlgorithm));
$binary = base64_decode($encrypted);
$iv = substr($binary, 0, openssl_cipher_iv_length(self::$cipherAlgorithm));
$data = substr($binary, openssl_cipher_iv_length(self::$cipherAlgorithm));
$key = openssl_digest($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'], self::$hashAlgorithm, true);
// Decrypt data.
$decrypted = openssl_decrypt($data, self::$cipherAlgorithm, $key, 0, $iv);
$decrypted = openssl_decrypt($data, self::$cipherAlgorithm, $key, OPENSSL_RAW_DATA, $iv);
return $decrypted;
}

@@ -282,10 +283,10 @@ class Helper
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length(self::$cipherAlgorithm));
$key = openssl_digest($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'], self::$hashAlgorithm, true);
// Encrypt data.
$encrypted = openssl_encrypt($string, self::$cipherAlgorithm, $key, 0, $iv);
$encrypted = openssl_encrypt($string, self::$cipherAlgorithm, $key, OPENSSL_RAW_DATA, $iv);
// Merge initialisation vector and encrypted data.
if ($encrypted !== false) {
$encrypted = $iv . $encrypted;
$encrypted = base64_encode($iv . $encrypted);
}
return $encrypted;
}


Loading…
Cancel
Save