1
0
Fork 0
mirror of synced 2024-07-06 07:00:56 +12:00
appwrite/tests/unit/OpenSSL/OpenSSLTest.php

31 lines
720 B
PHP
Raw Normal View History

2019-12-27 01:09:17 +13:00
<?php
2022-08-01 22:22:04 +12:00
namespace Tests\Unit\OpenSSL;
2019-12-27 01:09:17 +13:00
use Appwrite\OpenSSL\OpenSSL;
2019-12-27 01:09:17 +13:00
use PHPUnit\Framework\TestCase;
class OpenSSLTest extends TestCase
{
2020-10-01 10:53:38 +13:00
public function setUp(): void
2019-12-27 01:09:17 +13:00
{
}
2020-10-01 10:53:38 +13:00
public function tearDown(): void
2019-12-27 01:09:17 +13:00
{
}
2022-08-01 22:22:04 +12:00
public function testEncryptionAndDecryption(): void
2019-12-27 01:09:17 +13:00
{
$key = 'my-secret-key';
$iv = '';
$method = OpenSSL::CIPHER_AES_128_GCM;
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength($method));
$tag = null;
$secret = 'my secret data';
$data = OpenSSL::encrypt($secret, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag);
$this->assertEquals(OpenSSL::decrypt($data, $method, $key, 0, $iv, $tag), $secret);
}
2020-10-01 10:53:38 +13:00
}