CryptoService (since version 2.0)
Type Service
Methods
Description
A set of cryptologic and coding functions.
Examples
<?php
echo '<h1>Crypting</h1>';
// Encryption.
CryptoService::encrypt('I am a secret string. Please, don\'t make me public.' , 'password 123');
$encryptedString = CryptoService::get ();
echo 'Encrypted: ' .$encryptedString;
echo '<br />';
// Decryption with wrong key.
CryptoService::decrypt($encryptedString , 'Password 123');
echo 'With wrong key: ' . CryptoService::get ();
echo '<br />';
// Decryption with correct key.
CryptoService::decrypt($encryptedString , 'password 123');
echo 'With correct key: ' . CryptoService::get ();
echo '<br />';
echo '<br />';
echo '<h1>Hash algos</h1>';
// Example string for testing hash functions.
$myString = 'I am a test string.';
echo 'Test string: ' . $myString . '<br />';
echo 'BKDRHash: ' . CryptoService::BKDRHash ($myString) . '<br />';
echo 'SDBMHash: ' . CryptoService::SDBMHash ($myString) . '<br />';
echo 'DJBHash: ' . CryptoService::DJBHash ($myString) . '<br />';
echo '<br />';
echo '<h1>Coding</h1>';
$encoded = CryptoService::encodeString ($myString);
echo 'Encoded: ' . $encoded . '<br />';
echo 'Decoded: ' . CryptoService::decodeString ($encoded). '<br />';
echo '<br />';
echo '<h1>Random passwords</h1>';
echo ' 8 chars (alphanumeric): ' . CryptoService::generatePassword (8 , true) . '<br />';
echo ' 8 chars (mixed): ' . CryptoService::generatePassword (8 , false) . '<br />';
?>
echo '<h1>Crypting</h1>';
// Encryption.
CryptoService::encrypt('I am a secret string. Please, don\'t make me public.' , 'password 123');
$encryptedString = CryptoService::get ();
echo 'Encrypted: ' .$encryptedString;
echo '<br />';
// Decryption with wrong key.
CryptoService::decrypt($encryptedString , 'Password 123');
echo 'With wrong key: ' . CryptoService::get ();
echo '<br />';
// Decryption with correct key.
CryptoService::decrypt($encryptedString , 'password 123');
echo 'With correct key: ' . CryptoService::get ();
echo '<br />';
echo '<br />';
echo '<h1>Hash algos</h1>';
// Example string for testing hash functions.
$myString = 'I am a test string.';
echo 'Test string: ' . $myString . '<br />';
echo 'BKDRHash: ' . CryptoService::BKDRHash ($myString) . '<br />';
echo 'SDBMHash: ' . CryptoService::SDBMHash ($myString) . '<br />';
echo 'DJBHash: ' . CryptoService::DJBHash ($myString) . '<br />';
echo '<br />';
echo '<h1>Coding</h1>';
$encoded = CryptoService::encodeString ($myString);
echo 'Encoded: ' . $encoded . '<br />';
echo 'Decoded: ' . CryptoService::decodeString ($encoded). '<br />';
echo '<br />';
echo '<h1>Random passwords</h1>';
echo ' 8 chars (alphanumeric): ' . CryptoService::generatePassword (8 , true) . '<br />';
echo ' 8 chars (mixed): ' . CryptoService::generatePassword (8 , false) . '<br />';
?>
Last change 10/15/2009