defined($name) && is_string(constant($name)) ? (string) constant($name) : null; $parts = []; foreach (self::NAMES as $name) { $v = $constant($name); if (!is_string($v) || !self::genuine($v)) { return null; } $parts[] = $v; } if (count(array_unique($parts)) !== count($parts)) { return null; // the same value used twice: not what WordPress generates } return hash_hkdf('sha256', implode("\0", $parts), SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES, self::INFO); } public static function genuine(string $v): bool { return strlen($v) >= 32 && !str_contains(strtolower($v), 'put your unique phrase here') && count(array_unique(str_split($v))) >= 8; } /** A value that proves the derived key is the same one as before without revealing it (stored in an option). */ public static function checkValue(string $rawKey): string { return hash_hmac('sha256', 'aiwend-key-check', $rawKey); } }