Source of file EncryptedText.php
Size: 1,920 Bytes - Last Modified: 2021-12-23T10:02:40+00:00
/var/www/docs.ssmods.com/process/src/code/fieldtypes/EncryptedText.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 | <?php class EncryptedText extends Text { public $is_encrypted = true; /** * @var AtRestCryptoService */ protected $service; public function __construct($name) { parent::__construct($name); $this->service = Injector::inst()->get('AtRestCryptoService'); } public function setValue($value, $record = array()) { if (array_key_exists($this->name, $record) && $value === null) { $this->value = $record[$this->name]; } else { $this->value = $value; } } public function getDecryptedValue($value) { // Test if we're actually an encrypted value; if (ctype_xdigit($value) && strlen($value) > 130) { try { return $this->service->decrypt($value); } catch (Exception $e) { // We were unable to decrypt. Possibly a false positive, but return the unencrypted value return $value; } } return $value; } public function getValue() { return $this->getDecryptedValue($this->value); // TODO: Change the autogenerated stub } public function requireField() { $values = array( 'type' => 'text', 'parts' => array( 'datatype' => 'text', // 'precision' => $this->service->calculateRequiredFieldSize(strlen('Y-m-d H:i:s')), 'null' => 'not null', 'default' => $this->defaultVal, 'arrayValue' => $this->arrayValue ) ); DB::require_field($this->tableName, $this->name, $values); } public function prepValueForDB($value) { $value = parent::prepValueForDB($value); $ciphertext = $this->service->encrypt($value); $this->value = $ciphertext; return $ciphertext; } } |