base64_encode( $nonce ), 'box' => base64_encode( $box ) ], DAY_IN_SECONDS ); } /** The stashed password, or null when it expired, was forgotten or the salt changed. */ public static function read( string $job_id ): ?string { $t = get_transient( self::TRANSIENT . $job_id ); $nonce = is_array( $t ) ? base64_decode( (string) ( $t['nonce'] ?? '' ), true ) : false; $box = is_array( $t ) ? base64_decode( (string) ( $t['box'] ?? '' ), true ) : false; if ( ! is_string( $nonce ) || ! is_string( $box ) || SODIUM_CRYPTO_SECRETBOX_NONCEBYTES !== strlen( $nonce ) ) { return null; } $plain = sodium_crypto_secretbox_open( $box, $nonce, self::key() ); return is_string( $plain ) && '' !== $plain ? $plain : null; } public static function forget( string $job_id ): void { delete_transient( self::TRANSIENT . $job_id ); } private static function key(): string { return sodium_crypto_generichash( wp_salt( 'auth' ), '', SODIUM_CRYPTO_SECRETBOX_KEYBYTES ); } }