RealAESEncryptionMethod.php in Real AES 8
File
src/Plugin/EncryptionMethod/RealAESEncryptionMethod.php
View source
<?php
namespace Drupal\real_aes\Plugin\EncryptionMethod;
use Drupal\encrypt\EncryptionMethodInterface;
use Drupal\encrypt\Plugin\EncryptionMethod\EncryptionMethodBase;
use Defuse\Crypto\Crypto;
use Defuse\Crypto\Exception as Ex;
class RealAESEncryptionMethod extends EncryptionMethodBase implements EncryptionMethodInterface {
public function checkDependencies($text = NULL, $key = NULL) {
$errors = array();
if (!class_exists('\\Defuse\\Crypto\\Crypto')) {
$errors[] = t('Defuse PHP Encryption library is not correctly installed.');
}
if (strlen($key) != 16) {
$errors[] = t('This encryption method requires a 128 bit key.');
}
return $errors;
}
public function encrypt($text, $key, $options = array()) {
try {
return Crypto::encrypt($text, $key);
} catch (Ex\CryptoTestFailed $ex) {
return FALSE;
} catch (Ex\CannotPerformOperation $ex) {
return FALSE;
}
}
public function decrypt($text, $key, $options = array()) {
try {
return Crypto::decrypt($text, $key);
} catch (Ex\CryptoTestFailed $ex) {
return FALSE;
} catch (Ex\CannotPerformOperation $ex) {
return FALSE;
}
}
}