Keys.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace Lcobucci\JWT;
  3. use Lcobucci\JWT\Signer\Keychain;
  4. /**
  5. * @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
  6. */
  7. trait Keys
  8. {
  9. /**
  10. * @var array
  11. */
  12. protected static $rsaKeys;
  13. /**
  14. * @var array
  15. */
  16. protected static $ecdsaKeys;
  17. /**
  18. * @beforeClass
  19. */
  20. public static function createRsaKeys()
  21. {
  22. $keychain = new Keychain();
  23. $dir = 'file://' . __DIR__;
  24. static::$rsaKeys = [
  25. 'private' => $keychain->getPrivateKey($dir . '/rsa/private.key'),
  26. 'public' => $keychain->getPublicKey($dir . '/rsa/public.key'),
  27. 'encrypted-private' => $keychain->getPrivateKey($dir . '/rsa/encrypted-private.key', 'testing'),
  28. 'encrypted-public' => $keychain->getPublicKey($dir . '/rsa/encrypted-public.key')
  29. ];
  30. }
  31. /**
  32. * @beforeClass
  33. */
  34. public static function createEcdsaKeys()
  35. {
  36. $keychain = new Keychain();
  37. $dir = 'file://' . __DIR__;
  38. static::$ecdsaKeys = [
  39. 'private' => $keychain->getPrivateKey($dir . '/ecdsa/private.key'),
  40. 'private-params' => $keychain->getPrivateKey($dir . '/ecdsa/private2.key'),
  41. 'public1' => $keychain->getPublicKey($dir . '/ecdsa/public1.key'),
  42. 'public2' => $keychain->getPublicKey($dir . '/ecdsa/public2.key'),
  43. 'public-params' => $keychain->getPublicKey($dir . '/ecdsa/public3.key'),
  44. ];
  45. }
  46. }