phpseclib/src/e98b4edc-25b9-49d7-98a0-e42.../code.power

37 lines
842 B
Plaintext
Raw Permalink Normal View History

2023-04-15 15:00:08 +00:00
/**
* Encrypt a string as needed
*
* @param string $string The string to encrypt
* @param string $key The encryption key
*
* @return string
* @since 3.2.0
**/
public function encrypt(string $string, string $key): string
{
2023-10-24 08:36:46 +00:00
// Get the encryption object.
$aes = new Aes($key, 128);
2023-04-15 15:00:08 +00:00
2023-10-24 08:36:46 +00:00
return $aes->decryptString($string);
2023-04-15 15:00:08 +00:00
}
/**
* Decrypt a string as needed
*
* @param string $string The string to decrypt
* @param string $key The decryption key
*
2023-10-24 08:36:46 +00:00
* @return string|null
2023-04-15 15:00:08 +00:00
* @since 3.2.0
**/
2023-10-24 08:36:46 +00:00
public function decrypt(string $string, string $key): ?string
2023-04-15 15:00:08 +00:00
{
2023-10-24 08:36:46 +00:00
// Get the encryption object.
$aes = new Aes($key, 128);
2023-04-15 15:00:08 +00:00
2023-10-24 08:36:46 +00:00
try {
return $aes->decryptString($string);
} catch (\Exception $ex) {
2023-04-15 15:00:08 +00:00
return null;
}
2023-10-24 08:36:46 +00:00
}