PHP code example of spryker / propel-encryption-behavior

1. Go to this page and download the library: Download spryker/propel-encryption-behavior 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/ */

    

spryker / propel-encryption-behavior example snippets


// Before any database queries:

    use Spryker\PropelEncryptionBehavior\Cipher;
    Cipher::createInstance("mysecretpassphrase");


// In your application:

    $o = new MyClass();

    $o->setMyData("Some data that will remain as plain text.");
    $o->setMySecretData("Some data that will be encrypted.");

    $o->save();

// Later:

    $o = MyClassQuery::create()->findOneByMyData("Some data that will remain as plain text.");

    echo $o->getMySecretData();
    // "Some data that will be encrypted."

    // If you need to use different passphrases in different queries:

    use Spryker\PropelEncryptionBehavior\Cipher;

    Cipher::resetInstance();
    Cipher::createInstance("mysecretpassphrase_2");

    // ... read or write data with another passphrase

    // Intialize the cipher
    Cipher::createInstance($my_passphrase);