AsymmetricalEncryptionMethod.php in Encrypt 8.3
File
tests/src/Kernel/AsymmetricalEncryptionMethod.php
View source
<?php
namespace Drupal\Tests\encrypt\Kernel;
use Drupal\encrypt\Entity\EncryptionProfile;
use Drupal\encrypt\Exception\EncryptionMethodCanNotDecryptException;
use Drupal\KernelTests\KernelTestBase;
use Drupal\key\Entity\Key;
class AsymmetricalEncryptionMethod extends KernelTestBase {
protected static $modules = [
'key',
'encrypt',
'encrypt_test',
];
protected $encryptionProfile;
protected function setUp() {
parent::setUp();
$key = Key::create([
'id' => 'testing_key_128',
'label' => 'Testing Key 128 bit',
'key_type' => "encryption",
'key_type_settings' => [
'key_size' => '128',
],
'key_provider' => 'config',
'key_provider_settings' => [
'key_value' => 'mustbesixteenbit',
],
]);
$key
->save();
$this->encryptionProfile = EncryptionProfile::create([
'id' => 'test_encryption_profile',
'label' => 'Test Encryption profile',
'encryption_method' => 'asymmetrical_encryption_method',
'encryption_key' => $key
->id(),
]);
$this->encryptionProfile
->save();
}
public function testEncryptDecrypt() {
$service = $this->container
->get('encryption');
$text_encrypted = $service
->encrypt('Test to encrypt', $this->encryptionProfile);
$this
->assertEquals('###encrypted###', $text_encrypted);
$this
->expectException(EncryptionMethodCanNotDecryptException::class);
$service
->decrypt($text_encrypted, $this->encryptionProfile);
}
}