Download the PHP package cleaniquecoders/pii-protection without Composer

On this page you can find all versions of the php package cleaniquecoders/pii-protection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package pii-protection

PII Protection

Latest Version on Packagist Tests Total Downloads PHP Version

Pure-PHP PII protection: field-level encryption at rest + masking of sensitive fields in audit/log payloads. No framework, no global state — plain classes with explicit inputs and outputs, usable anywhere.

A small library of portable primitives every app handling personal data (SOC 2 / PDPA / GDPR) needs:

Everything is constructor-injected. No service container, no boot conventions, no static facades — so it drops into Laravel, Symfony, Slim, a CLI tool, a queue worker, or plain PHP unchanged.

Requirements

Installation

You can install the package via composer:

Usage

Quick start

Masking strategies

Each strategy implements MaskStrategy::mask(string $value): string.

Strategy Behaviour Reversible
TailStrategy Keep last N chars, mask the rest (******6789) No
FullStrategy Mask every char (**********) No
EmailStrategy Mask local-part, keep domain (****@acme.com) No
HashStrategy Replace with a one-way sha256 digest No
CreditCardStrategy Keep last 4 digits, preserve grouping (**** **** **** 1111) No
IpStrategy Mask the last octet/group (192.168.1.**) No
NameStrategy Keep each word's initial (J*** D**) No
NricStrategy Mask MyKad digits, keep dashes (******-**-****) No
RedactedStrategy Replace with a fixed placeholder ([redacted]) — hides the length too No

Every strategy takes an optional maskChar (default *) so you can render with , x, or any character:

Encryption at rest

OpenSslEncrypter uses AES-256-GCM. The key is injected via the constructor — the library never reads env/config. Each message uses a random IV and a random HKDF salt, so encrypting the same value twice yields different ciphertext.

Ciphertext is written in a self-describing, versioned format (v2.<keyId>.<payload>). Ciphertext produced by 1.0/1.1 still decrypts unchanged — upgrades are seamless.

Context binding (AAD) — bind ciphertext to a context (user id, column name) so it cannot be moved between rows/columns. The same context is required to decrypt:

Key rotation — give it a KeyRing with multiple keys: new ciphertext uses the current key, while older ciphertext keeps decrypting with whichever key its id points to. No big-bang re-encryption needed.

Searchable lookups (blind index)

Encryption is non-deterministic, so you cannot query an encrypted column. Store a deterministic HmacBlindIndex alongside the ciphertext and query that instead — it is one-way and only confirms a match, never reveals the value.

Scrubbing free text

PiiScrubber masks PII patterns inside free text (log lines, messages), not just named fields — with built-in detectors for email, credit card, Malaysian NRIC, IPv4 and phone numbers.

Or mask any custom pattern with RegexStrategy:

Scrubbing secrets

SecretScrubber is the sibling of PiiScrubber for machine credentials — keys, tokens and passwords rather than personal data. The two detector sets are deliberately disjoint: scrubbing every IP address and email out of an infrastructure log removes exactly the detail needed to debug it.

Note what survives. Which variable leaked, and which host it pointed at, is most of the value of the log line — only the credential is removed.

Detectors: private_key (PEM blocks), url_credentials, jwt, aws_access_key_id, authorization (Bearer/Basic), assignment (SECRET_KEY=…, "api_token": …).

When you already hold the secrets, LiteralScrubber masks them by exact match — certain where a pattern is a guess:

It sorts longest-first so a short secret nested inside a longer one cannot corrupt it, skips values under 6 characters, and skips pure digits so ports and counts stay readable. prepare() shows what survived those rules.

Use both: patterns catch secrets you never issued, literals catch the ones with no distinctive shape.

Redaction of payloads

ArrayRedactor generalises change-log masking: given a payload (e.g. with old_values / new_values, or any nested key/value map) and a list of sensitive fields, it applies the chosen MaskStrategy to each listed field — recursing into nested arrays and JSON-decoded structures — and leaves every other field untouched.

Per-field strategies — map each field to its own strategy in a single pass (plain field names still use the redactor's default strategy):

Dot-path & wildcard targeting — target a precise location instead of any key with that name; * matches any key at that level:

Redacting objects / DTOs

Tag properties with #[Pii] and let ObjectRedactor mask them into an array. A tag can name its own strategy; otherwise the redactor's default is used.

Tokenization

Swap a PII value for an opaque, random token and keep the mapping in a Vault. An in-memory ArrayVault ships with the package; implement Vault to persist tokens elsewhere.

Errors

Encryption/decryption failures throw a typed exception under CleaniqueCoders\PiiProtection\Exceptions\: EncryptionException and DecryptionException, both extending PiiException (itself a RuntimeException, so existing catch blocks keep working).

Guardrail — never encrypt lookup values

Never query on an encrypted column. Ciphertext is non-deterministic (random IV + salt per call) and will not match across rows or queries. To support equality lookups, store an HmacBlindIndex alongside the ciphertext and query that — or mask/hash the value if you don't need to reverse it.

Architecture

Design notes

  1. Single responsibility per class. Strategies, encrypter, redactor, and the wrapper are independent and swappable; consumers depend on the contracts, not the concretions.
  2. Configurable visible tail. TailStrategy(visible: N) — default 4.
  3. Nested / JSON PII. ArrayRedactor recurses, so structured columns are covered, not just flat scalars.
  4. Key handling is the caller's job. OpenSslEncrypter takes a key (or a KeyRing) in its constructor; the library never reads env/config. Rotation is supported via the ring, but loading/storing keys is up to you.

Documentation

Full documentation lives in docs/:

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of pii-protection with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
ext-mbstring Version *
ext-openssl Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package cleaniquecoders/pii-protection contains the following files

Loading the files please wait ...