PHP code example of wpelevator / encrypted-secrets

1. Go to this page and download the library: Download wpelevator/encrypted-secrets 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/ */

    

wpelevator / encrypted-secrets example snippets


$secret_storage = new WPElevator\Encrypted_Secrets\Encryption_Key_Storage_Memory( 'MY_SECRET_CONSTANT' );
$secret_key = $secret_storage->get();

if ( $secret_key ) {
	// Do something.
}

 return array (
  'key' => 'CgqSFJ3VJnZwj8UHNg3pwGUV4XeIVGSBqNzyxBUAZhI=',
  'created' => 1742299697,
);

$secret_storage = new WPElevator\Encrypted_Secrets\Encryption_Key_Storage_PHP_File( '/path/to/secret.php' );
$encryption_key = $secret_storage->get_key();

if ( ! $encryption_key && $secret_storage->is_supported() ) {
	$secret_storage->set_key( '...' );
	$encryption_key = $secret_storage->get_key();
}

if ( $encryption_key ) {
	// Do something.
}

$secret_storage = new WPElevator\Encrypted_Secrets\Encryption_Key_Storage_PHP_File( '/path/to/secret.php' );
$encryption = new WPElevator\Encrypted_Secrets\Encryption_Provider_Sodium_Compat();

if ( $encryption->is_supported() ) {
	$encryption_key = $secret_storage->get_key();

	// Generate an encryption key, if not configured.
	if ( ! $encryption_key && $secret_storage->is_supported() ) {
		$secret_storage->set_key( $encryption->generate_key() );
		$encryption_key = $secret_storage->get_key();
	}

	if ( $secret_key ) {
		$encrypted = $encryption->encrypt( 'my secret', $encryption_key ); // Encrypt.
		$decrypted = $encryption->decrypt( $encrypted, $encryption_key ); // Decrypt.
	}
}