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

Easy Ecc Laravel Package

paragonie/easy-ecc

Easy-ECC is a hardened, easy-to-use PHP wrapper around paragonie/phpecc for elliptic-curve crypto. Generate keypairs, sign/verify messages, and perform ECDH key exchange with Curve25519 or ECDSA curves (K256, P256, P384, P521).

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Strengths:

    • Security-First Design: Built on paragonie/phpecc (a hardened fork of mdanter/ecc), with constant-time algorithms to mitigate timing attacks—a critical requirement for cryptographic operations in Laravel/PHP applications.
    • Multi-Curve Support: Supports Curve25519 (default), secp256k1, NIST P-256/384/521, and ECDSA-specific features, enabling flexibility for compliance (e.g., FIPS 140-2) or blockchain use cases.
    • Defuse Integration: Seamless asymmetric encryption via defuse/php-encryption, reducing dependency sprawl for hybrid encryption (e.g., TLS, PGP-like workflows).
    • OpenSSL Compatibility: PEM serialization for interoperability with existing systems (e.g., legacy PHP OpenSSL wrappers).
  • Fit for Laravel:

    • Authentication/Authorization: Ideal for JWT signing (via ECDSA) or passwordless auth (e.g., WebAuthn with Curve25519).
    • Data Protection: Enables field-level encryption (e.g., encrypting sensitive PII in databases) without reinventing symmetric crypto.
    • API Security: Supports mutual TLS (mTLS) or service-to-service auth via key exchange (X25519).
    • Event Signing: Tamper-proof event dispatching (e.g., Laravel Events with signed payloads).
  • Weaknesses:

    • No Active Dependents: Lack of ecosystem adoption may indicate niche use cases (though this is offset by ParagonIE’s reputation).
    • PHP 8.4+ Focus: Recent updates target modern PHP, which may require Laravel version alignment (e.g., Laravel 10+).
    • No Laravel-Specific Integrations: Requires manual abstraction (e.g., wrapping in a CryptoService facade).

Integration Feasibility

  • Laravel Compatibility:

    • Service Container: Easy to register as a singleton in config/app.php or via a service provider.
    • Facades: Can be wrapped in a Crypto facade for consistency with Laravel’s patterns.
    • Artisan Commands: Useful for key generation/management (e.g., php artisan crypto:generate-keypair).
    • Event Listeners: Sign/verify events (e.g., Illuminate\Queue\Events\JobProcessed).
  • Database Integration:

    • Store keys in encrypted Laravel Vault or AWS KMS (avoid plaintext in .env).
    • Use Laravel Encryption for symmetric keys derived from ECC (e.g., via Defuse integration).
  • Caching:

    • Cache public keys (e.g., Redis) for performance, but never private keys.
    • Use Illuminate\Cache\Repository with a crypto tag for invalidation.

Technical Risk

  • Key Management:
    • Risk: Private keys in codebase or unencrypted storage.
    • Mitigation: Use Laravel’s Vault or environment variables with strict permissions.
  • Performance:
    • Risk: ECC operations are CPU-intensive; may bottleneck high-throughput APIs.
    • Mitigation: Benchmark with Curve25519 (fastest) vs. P-521 (slowest). Offload to a queue worker for non-critical paths.
  • Upgrade Path:
    • Risk: Breaking changes in phpecc (e.g., PHP 8.4+ deprecations).
    • Mitigation: Pin paragonie/easy-ecc to ^1.3 in composer.json and monitor ParagonIE’s releases.
  • Side-Channel Attacks:
    • Risk: Even with constant-time algorithms, misusage (e.g., logging keys) could expose vulnerabilities.
    • Mitigation: Enforce secure defaults (e.g., auto-destruct private keys after use).

Key Questions

  1. Use Case Prioritization:
    • Is this for authentication, data encryption, or integrity verification? Prioritize curves accordingly (e.g., Curve25519 for auth, P-256 for compliance).
  2. Key Lifecycle:
    • How will keys be rotated? Will you use Laravel’s config/caching.php for key expiration?
  3. Interoperability:
    • Do you need to exchange keys with non-PHP systems (e.g., JavaScript via libsodium.js)? Use Curve25519 for cross-language support.
  4. Compliance:
    • Are NIST curves (P-256, P-384) required for regulatory reasons (e.g., HIPAA, PCI-DSS)?
  5. Fallbacks:
    • Should legacy systems support phpecc (non-libsodium) mode for backward compatibility?

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Authentication: Replace Illuminate\Auth\GeneratesUserIds with ECDSA-signed tokens (e.g., ecc->sign($userId)).
    • API Security: Use Defuse integration for request/response encryption (e.g., encrypting Illuminate\Http\Request payloads).
    • Queues: Sign job payloads to prevent replay attacks (e.g., JobProcessed events).
    • Caching: Encrypt sensitive cache values (e.g., Cache::put('user_token', $ecc->seal($token, $publicKey))).
  • Third-Party Integrations:
    • AWS KMS: Use ECC keys to derive KMS keys (e.g., ecc->keyExchange() for key wrapping).
    • Stripe/Webhooks: Verify webhook signatures with ECDSA.
    • GraphQL: Encrypt query variables for sensitive fields.

Migration Path

  1. Phase 1: Proof of Concept

    • Add paragonie/easy-ecc to composer.json.
    • Implement a CryptoService facade with basic methods:
      // app/Services/CryptoService.php
      class CryptoService {
          public function __construct(private EasyECC $ecc) {}
      
          public function generateKeypair(): array {
              $sk = $this->ecc->generatePrivateKey();
              return [
                  'private' => $sk->exportPem(),
                  'public' => $sk->getPublicKey()->exportPem(),
              ];
          }
      
          public function sign(string $message, string $privateKeyPem): string {
              $sk = $this->ecc->importPrivateKey($privateKeyPem);
              return $this->ecc->sign($message, $sk)->toString();
          }
      }
      
    • Register in AppServiceProvider:
      $this->app->singleton(EasyECC::class, fn() => new EasyECC('P256'));
      $this->app->singleton(CryptoService::class);
      
  2. Phase 2: Core Integration

    • Authentication: Replace password hashing with ECDSA-signed tokens (e.g., Sanctum or Passport).
    • Database: Encrypt sensitive fields (e.g., encrypted_email) using Defuse:
      $defuse = new Defuse($this->ecc);
      $encrypted = $defuse->seal($user->email, $user->publicKey);
      
    • API: Add X-ECC-Signature header for request validation.
  3. Phase 3: Scaling

    • Key Rotation: Implement a KeyRotationService to cycle keys periodically.
    • Performance: Offload crypto to a queue worker (e.g., encrypt jobs).
    • Monitoring: Log crypto operations (e.g., ecc->sign() calls) via Laravel Telescope.

Compatibility

  • PHP Versions: Tested on PHP 8.1+; Laravel 10+ recommended.
  • Curve Selection:
    • Curve25519: Best for performance and cross-language support.
    • NIST Curves: Required for compliance (e.g., P-256 for FIPS).
  • Existing Crypto:
    • OpenSSL: Use PEM exports for interop (e.g., openssl_pkey_get()).
    • Libsodium: Easy-ECC defaults to libsodium where available (fallback to phpecc).

Sequencing

  1. Start Small: Begin with non-critical features (e.g., signing logs).
  2. Critical Path: Secure authentication and data encryption next.
  3. Optimize: Profile and offload heavy operations (e.g., P-521 key exchanges).
  4. Deprecate Legacy: Phase out weak crypto (e.g., RSA) in favor of ECC.

Operational Impact

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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky