4use Ubiquity\config\Configuration;
38 $oldKey = $config[self::ENCRYPTION_KEY_NAME] ??
null;
39 self::getInstance($oldKey, $cipher);
40 self::$encryptionInstance->initializeKeyAndCipher();
41 $key = self::$encryptionInstance->getKey();
43 if ($oldKey !== $key) {
44 $oConfig = Configuration::loadConfigWithoutEval(
'config');
45 $oConfig[self::ENCRYPTION_KEY_NAME] =
"getenv('".self::ENCRYPTION_KEY_NAME.
"')";
47 $envArray[self::ENCRYPTION_KEY_NAME]=$key;
49 Startup::saveConfig($oConfig);
59 public static function startProd(array $config, ?
string $cypher =
null) {
60 $key = $config[self::ENCRYPTION_KEY_NAME];
70 public static function encrypt($data): string {
71 if (is_string($data)) {
72 return self::$encryptionInstance->encryptString($data);
74 return self::$encryptionInstance->encrypt($data);
84 return self::$encryptionInstance->decryptString($data);
94 public static function decrypt(
string $data, $unserialize =
true) {
95 return self::$encryptionInstance->decrypt($data, $unserialize);
104 public static function generateKey(?
string $cipher = Encryption::AES128): string {
105 return self::getInstance(null)->generateKey($cipher ??
Encryption::AES128);
109 return self::getInstance(self::getKey())->getKey();
113 return self::$encryptionInstance;
117 return isset(self::$encryptionInstance);
static load(?string $path=null, string $filename='.env')
Loads an env file an returns an array of key/value pairs.
static save(array $content,?string $path=null, string $filename='.env')
Saves a content array on disk.
Ubiquity\security\data$Encryption This class is part of Ubiquity Inspired from illuminate/encryption ...
static getCipherFromKey(string $key)
Ubiquity\security\data$EncryptionManager This class is part of Ubiquity.
static decrypt(string $data, $unserialize=true)
Decrypt the given data with possible unserialization.
static decryptString(string $data)
Decrypt the given string.
static getInstance(?string $key, ?string $cypher=Encryption::AES128)
static start(array &$config, ?string $cipher=Encryption::AES128)
Start the manager and generate the encryption key.
static getEncryptionInstance()
const ENCRYPTION_KEY_NAME
static startProd(array $config, ?string $cypher=null)
Start the encryption manager for production.
static $encryptionInstance
static generateKey(?string $cipher=Encryption::AES128)
Generate a new encryption key.
static encrypt($data)
Encrypt the given data.