OpenSSL cryptography adapter.
Constructor.
| Type | Description |
|---|---|
| array | Configuration |
NULL
public function __construct(array $config)
{
if(extension_loaded('openssl') === false)
{
throw new RuntimeException(vsprintf("%s(): OpenSSL is not available.", array(__METHOD__)));
}
$this->key = $config['key'];
$this->cipher = $config['cipher'];
}
Encrypts data.
| Type | Description |
|---|---|
| string | String to encrypt |
string
public function encrypt($string)
{
return openssl_encrypt($string, $this->cipher, $this->key);
}
Decrypts data.
| Type | Description |
|---|---|
| string | String to decrypt |
string
public function decrypt($string)
{
return openssl_decrypt($string, $this->cipher, $this->key);
}