CryptoTest.php 668 B

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