Encryptor.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Libs\TikTok\MiniProgram\Server;
  3. use App\Libs\TikTok\Kernel\Encryptor as BaseEncryptor;
  4. use App\Libs\TikTok\Kernel\Exceptions\DecryptException;
  5. use App\Libs\TikTok\Kernel\Exceptions\InvalidArgumentException;
  6. use App\Libs\TikTok\Kernel\Support\AES;
  7. /**
  8. * Class Encryptor.
  9. *
  10. * @author mingyoung <mingyoungcheung@gmail.com>
  11. */
  12. class Encryptor extends BaseEncryptor {
  13. /**
  14. * Decrypt data.
  15. *
  16. * @param string $sessionKey
  17. * @param string $iv
  18. * @param string $encrypted
  19. *
  20. * @return array
  21. *
  22. * @throws DecryptException|InvalidArgumentException
  23. */
  24. public function decryptData(string $sessionKey, string $iv, string $encrypted): array {
  25. $decrypted = AES::decrypt(
  26. base64_decode($encrypted),
  27. base64_decode($sessionKey),
  28. base64_decode($iv),
  29. );
  30. $decrypted = json_decode($decrypted, true);
  31. if (!$decrypted) {
  32. throw new DecryptException('The given payload is invalid.');
  33. }
  34. return $decrypted;
  35. }
  36. }