mirror of
https://github.com/appwrite/appwrite
synced 2026-04-25 23:47:19 +00:00
30 lines
688 B
PHP
30 lines
688 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Appwrite\Tests;
|
||
|
|
|
||
|
|
use OpenSSL\OpenSSL;
|
||
|
|
use PHPUnit\Framework\TestCase;
|
||
|
|
|
||
|
|
class OpenSSLTest extends TestCase
|
||
|
|
{
|
||
|
|
public function setUp()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
public function tearDown()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
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);
|
||
|
|
}
|
||
|
|
}
|