PHP code example of assistenzde / simple-cryptographic-bundle

1. Go to this page and download the library: Download assistenzde/simple-cryptographic-bundle 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/ */

    

assistenzde / simple-cryptographic-bundle example snippets


$cryptographicService = new SimpleCryptographicService('$ecr3t');

$encryptedString1 = $cryptographicService->encrypt('Hello world!');  // some encrypted string, i.e. 'ABCDEFG'
echo $cryptographicService->decrypt($encryptedString1);              // outputs 'Hello world!'

$encryptedString2 = $cryptographicService->encrypt('Hello world!');  // some encrypted string, i.e. 'HIJKLMNOP'
echo $cryptographicService->decrypt($encryptedString2);              // outputs 'Hello world!'



namespace MyNamespace;

use Assistenzde\SimpleCryptographicBundle\Service\SimpleCryptographicService;

/**
 * Class AuthenticationSubscriber
 */
final class MyClass
{
    /**
     * the crypto service to encode/dedoce strings
     * 
     * @var SimpleCryptographicService
     */
    protected SimpleCryptographicService $simpleCryptographicService;

    /**
     * MyClass constructor
     * 
     * @param SimpleCryptographicService $simpleCryptographicService
     */
    public function __construct(SimpleCryptographicService $simpleCryptographicService)
    {       
        $this->simpleCryptographicService = $simpleCryptographicService;
    }

    /**
     * 
     */
    public function doSomething()
    {       
         // do some calculation and get a user token
         
         // encrypt the user token        
         $encryptedUserToken = $this->simpleCryptographicService->encrypt($userToken);
         
         // and do some more stuff,
         // esp. use the encrypted token (i.e. as request parameter or to save in a file)

         // derypt the encrypted stuff        
         $userToken = $this->simpleCryptographicService->decrypt($encryptedUserToken); 
    }
}