PHP code example of 4cm / crypto

1. Go to this page and download the library: Download 4cm/crypto 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/ */

    

4cm / crypto example snippets




try {
    //
    (new crypto($keyPath))->generateKey();
    //
} catch (Exception $e) {
    //
    die($e->getMessage());
    //
}

//
$keyPath = '/path/to/subrootfolder/userid.key';
$Content = 'This is a message that we want to encrypt';
//
try {
    //
    $Content = (new crypto($keyPath, $Content, 'e'))->crypto();
    //
} catch (Exception $e) {
    //
    die('Encryption Error: ' . $e->getMessage());
    //
}

//
$keyPath = '/path/to/subrootfolder/kms/userid.key';
$EncryptedContent = 'XyjE80p/QF72xwHx6HSNJt8WKxodx0nKhDaNeCe0koxvQ=='; // just an example of encrypted content
//
try {
    //
    $Content = (new crypto($keyPath, $EncryptedContent, 'd'))->crypto();
    //
} catch (Exception $e) {
    //
    die('Decryption Error: ' . $e->getMessage());
    //
}