acf_decrypt()
Decrypts an encrypted string using PHP. https://bhoover.com/using-php-openssl_encrypt-openssl_decrypt-encrypt-decrypt-data/
Хуков нет.
Возвращает
string|false. Decrypted string, or false if the payload is malformed or decryption fails.
Использование
acf_decrypt( $data, $context );
- $data(строка)
- The string to decrypt.
По умолчанию:'' - $context(строка)
- Optional domain-separation label. Must match the context passed to acf_encrypt() at mint time. When empty, the legacy key derivation is used for back-compat with existing callers.
По умолчанию:''
Список изменений
| С версии 5.5.8 | Введена. |
Код acf_decrypt() acf decrypt ACF 6.8.11
function acf_decrypt( $data = '', string $context = '' ) {
if ( ! function_exists( 'openssl_decrypt' ) ) {
return false;
}
$raw = base64_decode( (string) $data, true );
if ( false === $raw ) {
return false;
}
if ( strlen( $raw ) <= 32 ) {
return false;
}
if ( '' === $context ) {
$key = wp_hash( 'acf_encrypt' );
$mac_key = wp_hash( 'acf_encrypt_mac' );
} else {
$key = wp_hash( 'acf_encrypt|' . $context );
$mac_key = wp_hash( 'acf_encrypt_mac|' . $context );
}
$hmac = substr( $raw, -32 );
$payload = substr( $raw, 0, -32 );
$mac_data = '' === $context ? $payload : ( $context . '|' . $payload );
$expected = hash_hmac( 'sha256', $mac_data, $mac_key, true );
if ( ! hash_equals( $expected, $hmac ) ) {
return false;
}
if ( strpos( $payload, '::' ) === false ) {
return false;
}
list( $encrypted_data, $iv ) = explode( '::', $payload, 2 );
return openssl_decrypt( $encrypted_data, 'aes-256-cbc', $key, 0, $iv );
}