1
0
Fork 0
mirror of synced 2024-07-03 05:31:38 +12:00
appwrite/tests/unit/OpenSSL/OpenSSLTest.php

31 lines
710 B
PHP
Raw Normal View History

2019-12-27 01:09:17 +13:00
<?php
namespace Appwrite\Tests;
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
{
}
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);
}
2020-10-01 10:53:38 +13:00
}