/** * Test adding an encryption profile and encrypting / decrypting with it. */ public function testEncryptAndDecrypt() { // Create an encryption profile config entity. $this->drupalGet('admin/config/system/encryption/profiles/add'); // Check if the plugin exists. $this->assertOption('edit-encryption-method', 'test_encryption_method', t('Encryption method option is present.')); $this->assertText('Test Encryption method', t('Encryption method text is present')); $edit = ['encryption_method' => 'test_encryption_method']; $this->drupalPostAjaxForm(NULL, $edit, 'encryption_method'); $edit = ['id' => 'test_encryption_profile', 'label' => 'Test encryption profile', 'encryption_method' => 'test_encryption_method', 'encryption_key' => $this->testKey->id()]; $this->drupalPostForm('admin/config/system/encryption/profiles/add', $edit, t('Save')); $encryption_profile = \Drupal::service('entity.manager')->getStorage('encryption_profile')->load('test_encryption_profile'); $this->assertTrue($encryption_profile, 'Encryption profile was succesfully saved.'); // Test the encryption service with our encryption profile. $test_string = 'testing 123 &*#'; $enc_string = \Drupal::service('encryption')->encrypt($test_string, $encryption_profile); $this->assertEqual($enc_string, 'zhfgorfvkgrraovggrfgvat 123 &*#', 'The encryption service is not properly processing'); // Test the decryption service with our encryption profile. $dec_string = \Drupal::service('encryption')->decrypt($enc_string, $encryption_profile); $this->assertEqual($dec_string, $test_string, 'The decryption service is not properly processing'); }
/** * {@inheritdoc} */ public function setEncryptionKey(Key $key) { $this->encryption_key_entity = $key; $this->encryption_key = $key->id(); }