CryptoTest.php 723 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace Tests\Unit;
  3. use phpseclib\Crypt\RSA;
  4. use PHPUnit\Framework\Attributes\Test;
  5. use Tests\TestCase;
  6. class CryptoTest extends TestCase
  7. {
  8. /**
  9. * A basic test to check if PHPSecLib is installed.
  10. *
  11. * @return void
  12. */
  13. #[Test]
  14. public function libraryInstalled()
  15. {
  16. $this->assertTrue(class_exists('\phpseclib\Crypt\RSA'));
  17. }
  18. #[Test]
  19. public function RSASigning()
  20. {
  21. $rsa = new RSA();
  22. extract($rsa->createKey());
  23. $rsa->loadKey($privatekey);
  24. $plaintext = 'pixelfed rsa test';
  25. $signature = $rsa->sign($plaintext);
  26. $rsa->loadKey($publickey);
  27. $this->assertTrue($rsa->verify($plaintext, $signature));
  28. }
  29. }