You are here

public function EncryptedFieldStorageItem::decrypt in Field Encryption 3.0.x

Decrypts the field item.

File

src/Plugin/Field/FieldType/EncryptedFieldStorageItem.php, line 85

Class

EncryptedFieldStorageItem
Plugin implementation of the 'encrypted_field_storage' field type.

Namespace

Drupal\field_encrypt\Plugin\Field\FieldType

Code

public function decrypt() {
  if ($this->value !== NULL) {

    // Use the field's encryption_profile if available. It should always be.
    $encryption_profile = (string) $this
      ->get('encryption_profile')
      ->getValue() ?: \Drupal::config('field_encrypt.settings')
      ->get('encryption_profile');
    return unserialize(\Drupal::service('encryption')
      ->decrypt(base64_decode($this->value), $this
      ->loadEncryptionProfile($encryption_profile)));
  }
  return NULL;
}