1
0
Fork 0
mirror of synced 2024-06-29 11:40:45 +12:00
appwrite/tests/unit/OpenSSL/OpenSSLTest.php
2020-09-30 17:53:38 -04:00

31 lines
710 B
PHP

<?php
namespace Appwrite\Tests;
use Appwrite\OpenSSL\OpenSSL;
use PHPUnit\Framework\TestCase;
class OpenSSLTest extends TestCase
{
public function setUp(): void
{
}
public function tearDown(): void
{
}
public function testEncryptionAndDecryption()
{
$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);
}
}