2018-08-23 04:45:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit;
|
|
|
|
|
2022-12-21 21:21:07 +00:00
|
|
|
use phpseclib\Crypt\RSA;
|
2018-08-23 04:45:25 +00:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class CryptoTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* A basic test to check if PHPSecLib is installed.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testLibraryInstalled()
|
|
|
|
{
|
|
|
|
$this->assertTrue(class_exists('\phpseclib\Crypt\RSA'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRSASigning()
|
|
|
|
{
|
2022-12-21 21:21:07 +00:00
|
|
|
$rsa = new RSA();
|
2018-08-23 04:45:25 +00:00
|
|
|
extract($rsa->createKey());
|
|
|
|
$rsa->loadKey($privatekey);
|
|
|
|
$plaintext = 'pixelfed rsa test';
|
|
|
|
$signature = $rsa->sign($plaintext);
|
|
|
|
$rsa->loadKey($publickey);
|
|
|
|
$this->assertTrue($rsa->verify($plaintext, $signature));
|
|
|
|
}
|
|
|
|
}
|