RsaEncryptionService.php 443 B

12345678910111213141516
  1. <?php
  2. namespace App\Service;
  3. class RsaEncryptionService extends Service
  4. {
  5. public function encrypt($data)
  6. {
  7. //公钥文件位于 storage/app/public/rsa/public.pem
  8. $publicKeyPath = storage_path('app/public/rsa/public.pem');
  9. $publicKey = openssl_pkey_get_public(file_get_contents($publicKeyPath));
  10. openssl_public_encrypt($data, $encrypted, $publicKey);
  11. return base64_encode($encrypted);
  12. }
  13. }