Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Rc4 Bundle Laravel Package

corley/rc4-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require corley/rc4-bundle
    

    Add to config/bundles.php:

    return [
        // ...
        Corley\RC4Bundle\CorleyRC4Bundle::class => ['all' => true],
    ];
    
  2. Configure Key: Add your RC4 key in config/packages/rc4.yaml (or parameters.yml for older Laravel):

    rc4:
        key: "your-32-character-secret-key-here"
    
  3. First Use Case: Inject the RC4 service into a controller or service:

    use Corley\RC4Bundle\Service\RC4Service;
    
    class MyController extends Controller
    {
        public function __construct(private RC4Service $rc4) {}
    
        public function encrypt()
        {
            $encrypted = $this->rc4->encrypt("plaintext");
            $decrypted = $this->rc4->decrypt($encrypted);
            return response()->json(['encrypted' => $encrypted]);
        }
    }
    

Implementation Patterns

Dependency Injection

  • Service Binding: Register the service in Laravel's container (if not auto-discovered):

    $this->app->bind(RC4Service::class, function ($app) {
        return new RC4Service($app['config']['rc4.key']);
    });
    
  • Usage in Services:

    class DataEncryptor
    {
        public function __construct(private RC4Service $rc4) {}
    
        public function secureData(string $data): string
        {
            return $this->rc4->encrypt($data);
        }
    }
    

Workflows

  1. API Security:

    • Encrypt sensitive data before storage:
      $user->api_token = $this->rc4->encrypt($token);
      $user->save();
      
    • Decrypt on retrieval:
      $token = $this->rc4->decrypt($user->api_token);
      
  2. Configuration Management:

    • Store secrets in config/rc4.php:
      return [
          'key' => env('RC4_KEY', 'fallback-key'),
      ];
      
  3. Middleware for Encryption:

    class EncryptPayloadMiddleware
    {
        public function handle($request, Closure $next)
        {
            $request->merge([
                'payload' => $this->rc4->encrypt($request->payload)
            ]);
            return $next($request);
        }
    }
    

Integration Tips

  • Laravel Facades: Create a facade for cleaner syntax:

    // app/Facades/RC4.php
    namespace App\Facades;
    
    use Illuminate\Support\Facades\Facade;
    
    class RC4 extends Facade
    {
        protected static function getFacadeAccessor() { return 'rc4'; }
    }
    

    Usage:

    $encrypted = RC4::encrypt("data");
    
  • Environment Variables: Use Laravel's .env for the key:

    RC4_KEY=your-32-character-secret-key-here
    

    Then reference in config/rc4.php:

    'key' => env('RC4_KEY'),
    

Gotchas and Tips

Pitfalls

  1. Key Length:

    • RC4 requires a 32-character key. Shorter keys will fail silently or produce incorrect output.
    • Validate in a service method:
      if (strlen($this->key) !== 32) {
          throw new \RuntimeException("RC4 key must be 32 characters long.");
      }
      
  2. Deprecated Package:

    • Last updated in 2015. Avoid for new projects; consider modern alternatives like openssl_encrypt or defuse/php-encryption.
    • If used, pin the version in composer.json:
      "corley/rc4-bundle": "dev-master"
      
  3. No Padding/Error Handling:

    • RC4 is stream cipher; no built-in padding for block ciphers. Handle edge cases manually:
      $this->rc4->encrypt(str_pad($data, 16, "\0")); // Example padding
      
  4. Symfony2 Legacy:

    • Designed for Symfony2. Laravel integration requires manual container binding or facade creation.

Debugging

  • Test Key: Use a known key/value pair to verify:

    $this->assertEquals("expected", $this->rc4->encrypt("test"));
    
  • Logging: Log encrypted/decrypted values for debugging:

    \Log::debug("RC4 Encrypted", ['data' => $encrypted]);
    

Extension Points

  1. Custom Service: Extend the service for additional methods:

    class ExtendedRC4Service extends RC4Service
    {
        public function hash(string $data): string
        {
            return hash('sha256', $this->encrypt($data));
        }
    }
    
  2. Configuration Overrides: Override the key dynamically:

    $this->app->singleton(RC4Service::class, function ($app) {
        return new RC4Service($app['config']['rc4.key'] ?? 'dynamic-key');
    });
    
  3. Event Listeners: Trigger events on encryption/decryption:

    $this->rc4->encrypt($data); // Listen for `rc4.encrypted` event
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle