acf_decrypt()ACF 5.5.8

Decrypts an encrypted string using PHP. https://bhoover.com/using-php-openssl_encrypt-openssl_decrypt-encrypt-decrypt-data/

No Hooks.

Returns

String|false. Decrypted string, or false if the payload is malformed or decryption fails.

Usage

acf_decrypt( $data );
$data(string)
The string to decrypt.
Default: ''

Changelog

Since 5.5.8 Introduced.

acf_decrypt() code ACF 6.8.8

function acf_decrypt( $data = '' ) {

	if ( ! function_exists( 'openssl_decrypt' ) ) {
		return false;
	}

	$raw = base64_decode( (string) $data, true );
	if ( false === $raw ) {
		return false;
	}

	if ( strlen( $raw ) <= 32 ) {
		return false;
	}

	$mac_key = wp_hash( 'acf_encrypt_mac' );
	$hmac    = substr( $raw, -32 );
	$payload = substr( $raw, 0, -32 );

	$expected = hash_hmac( 'sha256', $payload, $mac_key, true );
	if ( ! hash_equals( $expected, $hmac ) ) {
		return false;
	}

	if ( strpos( $payload, '::' ) === false ) {
		return false;
	}

	$key = wp_hash( 'acf_encrypt' );

	list( $encrypted_data, $iv ) = explode( '::', $payload, 2 );

	return openssl_decrypt( $encrypted_data, 'aes-256-cbc', $key, 0, $iv );
}