1. Go to this page and download the library: Download webiny/crypt 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/ */
webiny / crypt example snippets
class MyClass
{
use Webiny\Component\Crypt\CryptTrait;
function myMethod()
{
$this->crypt()->encrypt('to encrypt', 'secret key');
}
}
$randomInt = $crypt->generateRandomInt(10, 20); // e.g. 15
// generate a string from a defined set of characters
$randomString = $crypt->generateRandomString(5, 'abc'); // e.g. cabcc
// generate a string that contains only letters (lower & upper case and numbers)
$randomString = $crypt->generateUserReadableString(5); // A12uL
// generate a string that can contain special characters
$randomString = $crypt->generateHardReadableString(5); // &"!3g
// hash password
$passwordHash = $crypt->createPasswordHash('login123'); // $2y$08$GgGha6bh53ofEPnBawShwO5FA3Q8ImvPXjJzh662/OAWkjeejAJKa
// (on login page) verify the hash with the correct password
$passwordsMatch = $crypt->verifyPasswordHash('login123', $passwordHash); // true or false
// encrypt it
$encrypted = $crypt->encrypt('some data', 'abcdefgh12345678');
// decrypt it
$decrypted = $crypt->decrypt($result, 'abcdefgh12345678'); // "some data"