| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Source view] [Print] [Project Stats]
Secrets API: WP_Secrets_Cipher class
| File Size: | 409 lines (13 kb) |
| Included or required: | 0 times |
| Referenced: | 0 times |
| Includes or requires: | 0 files |
| encrypt_value( string $master_key, string $scope, int $site_id, string $name, string $slot, $plaintext ) X-Ref |
| Encrypts a plaintext into a single record slot. return: array|WP_Error Slot array with keys 'dk', 'dk_nonce', 'ct', 'nonce', param: string $master_key 32-byte master key for this scope. param: string $scope 'site' or 'network'. param: int $site_id Binds the AAD to a specific blog for site scope; use param: string $name The secret's namespaced name. param: string $slot A WP_Secret_Version constant. param: string $plaintext The value to encrypt. |
| decrypt_value( string $master_key, string $scope, int $site_id, string $name, string $slot, $record ) X-Ref |
| Decrypts a single record slot back to its plaintext. return: string|WP_Error Plaintext on success. WP_Error on failure. param: string $master_key 32-byte master key for this scope. param: string $scope 'site' or 'network'. Must match what encrypt_value() param: int $site_id Must match what encrypt_value() was called with. param: string $name Must match what encrypt_value() was called with. param: string $slot Must match what encrypt_value() was called with. param: mixed $record The slot array previously returned by encrypt_value(). |
| fingerprint( string $master_key, $plaintext ) X-Ref |
| Computes the keyed fingerprint of a plaintext under a master key. Keyed so a fingerprint is not a cross-site rainbow-table oracle: the same plaintext fingerprints differently under a different master key. Callers verifying a value against a previously stored fingerprint (for example, a migration's verify-before-delete step) must recompute this from freshly decrypted plaintext and compare – never trust a fingerprint read back from a record, which sits outside the AAD and is not authenticated. return: string|WP_Error 32-character hex string on success. WP_Error on failure. param: string $master_key 32-byte master key. param: string $plaintext Value to fingerprint. |
| build_aad( string $purpose, string $scope, int $site_id, string $name, string $slot ) X-Ref |
| Builds the AAD that binds a ciphertext to its full context. Binding covers purpose, scope, site, name, and slot, so that a record can never be replayed under any of them. Centralized in one place rather than inlined at each call site, and only ever called after validate_common() has confirmed $name passes wp_secrets_validate_name() – the validated character set contains no '|', which is what makes this delimiter safe to join on. return: string param: string $purpose One of the AAD_* class constants. param: string $scope 'site' or 'network'. param: int $site_id Blog id for site scope, 0 for network scope. param: string $name Validated secret name. param: string $slot A WP_Secret_Version constant. |
| validate_common( string $master_key, string $scope, int $site_id, string $name, string $slot ) X-Ref |
| Validates the parameters shared by encrypt_value() and decrypt_value(). $scope, $site_id, and $slot are never influenced by external input – every call site in this API supplies them internally – so a bad value here means the calling code is wrong, not that a runtime condition failed. That still reports as a WP_Error rather than an exception: WordPress functions return WP_Error or false, they do not throw. The _doing_it_wrong() notice is what makes the distinction visible during development. $name and $master_key legitimately vary at runtime (a plugin author's typo, an unavailable key backend) and have always reported the same way. return: true|WP_Error param: string $master_key Candidate master key. param: string $scope Candidate scope. param: int $site_id Candidate site id. param: string $name Candidate secret name. param: string $slot Candidate slot. |
| invalid_argument( string $message ) X-Ref |
| Reports a caller error the way WordPress does. Emits a _doing_it_wrong() notice for the developer, and returns a WP_Error the caller can act on. return: WP_Error param: string $message What the caller got wrong. |
| is_valid_master_key( string $master_key ) X-Ref |
| Whether a candidate value is usable as a 32-byte master key. return: bool param: string $master_key Candidate master key. |
| decode_record_fields( $record ) X-Ref |
| Validates and base64-decodes the four crypto fields of a record slot. return: array<string, string>|WP_Error Decoded ('dk', 'dk_nonce', 'ct', 'nonce') on success. param: mixed $record Candidate slot array. |
| Generated : Wed Oct 14 08:20:33 2026 | Cross-referenced by PHPXref |