1. Go to this page and download the library: Download robtimus/obfuscation library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$incorrectlyObfuscated = $obfuscator->obfuscateText('12345678901234');
// $incorrectlyObfuscated is '1234******1234' where '1234********34' would probably be preferred
// Keep only the TLD of the domain
$localPartObfuscator = Obfuscate::portion()
->keepAtStart(1)
->keepAtEnd(1)
->withFixedTotalLength(8)
->build();
$domainObfuscator = SplitPoint::atLast('.')->splitTo(Obfuscate::all(), Obfuscate::none());
$obfuscator = SplitPoint::atFirst('@')->splitTo($localPartObfuscator, $domainObfuscator);
$obfuscated = $obfuscator->obfuscateText('[email protected]');
// $obfuscated is 't******t@*******.org'
$obfuscator = new class extends Obfuscator
{
public function __construct()
{
parent::__construct();
}
public function obfuscateText(string $text): string
{
return strtoupper($text);
}
};
$obfuscated = $obfuscator->obfuscateText('Hello World');
// $obfuscated is 'HELLO WORLD'
$propertyObfuscator = PropertyObfuscator::builder()
->withProperty('password', Obfuscate::fixedLength(3))
->build();
$obfuscatedPassword = $propertyObfuscator->obfuscateProperty('password', 'admin1234');
// $obfuscatedPassword is '***'
$obfuscatedUsername = $propertyObfuscator->obfuscateProperty('username', 'admin');
// $obfuscatedUsername is 'admin'
$object = new stdClass();
$object->username = 'admin';
$object->password = 'admin1234';
$obfuscatedObject = $propertyObfuscator->obfuscateProperties($object);
// $obfuscatedObject is a stdClass with properties username='admin' and password='***'
$obfuscatedArray = $propertyObfuscator->obfuscateProperties(array('username' => 'admin', 'password' => 'admin1234'));
// $obfuscatedArray is ['username' => 'admin', 'password' => '***']
$propertyObfuscator = PropertyObfuscator::builder()
->withProperty('password', Obfuscate::fixedLength(3), false) // defaults to true
->forObjects(PropertyObfuscationMode::EXCLUDE) // defaults to INHERIT
->forArrays(PropertyObfuscationMode::EXCLUDE) // defaults to INHERIT
->build();
$propertyObfuscator = PropertyObfuscator::builder()
->caseInsensitiveByDefault() // defaults to case sensitive
->forObjectsByDefault(PropertyObfuscationMode::EXCLUDE) // defaults to INHERIT
->forArraysByDefault(PropertyObfuscationMode::EXCLUDE) // defaults to INHERIT
->withProperty('password', Obfuscate::fixedLength(3))
->build();