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

Halite Laravel Package

paragonie/halite

Halite is a high-level PHP cryptography library from Paragon Initiative Enterprises, built on libsodium. It provides safer, opinionated APIs for encryption, authentication, key management, and password hashing, helping you use modern crypto correctly with minimal foot-guns.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Strengths (Updated/Reinforced):

    • Enhanced Static Analysis: PHPStan (level 5) and Psalm 6 integration ensures stricter type safety, reducing runtime errors in Laravel integrations (e.g., incorrect key types or malformed encrypted data).
    • Security Hardening: Removal of final modifiers on private methods (PR #204) allows for deeper Laravel-specific subclassing (e.g., custom Halite wrappers for audit logging or key rotation hooks).
    • Test Coverage: Expanded test suite (PR #206) and fixed coverage badges improve confidence in edge cases (e.g., corrupted ciphertext, key derivation failures).
    • Modern PHP Practices: Continued alignment with PHP 8+ features (e.g., Psalm/PHPStan compatibility) future-proofs Laravel integrations.
  • Fit for Laravel (Reaffirmed):

    • Key Rotation: Private method flexibility enables Laravel-specific extensions (e.g., overriding deriveKey() to integrate with config/encryption.php).
    • Debugging: Static analysis tools (PHPStan/Psalm) can flag Laravel-specific anti-patterns (e.g., passing non-string keys to Halite::encrypt()).
  • Potential Misalignment (Unchanged):

    • Libsodium dependency and key management remain the primary integration risks.

Integration Feasibility

  • Laravel Ecosystem Synergy (Updated):

    • Static Analysis Hooks: Use PHPStan/Psalm to enforce Laravel-specific rules:
      // Example PHPStan rule for Halite keys
      rules:
        - methodcall:
            method: ParagonIE\Halite\Halite::encrypt
            args:
              - type: string
              - type: string
            message: "Halite keys must be base64-encoded."
      
    • Test Coverage: Leverage Halite’s expanded tests to validate Laravel integrations (e.g., HaliteEncryptsAttributes trait).
  • Example Integration (Updated):

    // Laravel-specific Halite wrapper with static analysis support
    class LaravelHalite extends Halite {
        public function encryptAttribute(string $value, string $key): string {
            return parent::encrypt($value, $this->normalizeKey($key));
        }
    
        private function normalizeKey(string $key): string {
            // Custom logic to fetch from Laravel's config/encryption.php
            return base64_encode($key);
        }
    }
    

Technical Risk

  • Static Analysis Overhead:

    • Risk: PHPStan/Psalm may introduce false positives for Laravel-specific patterns (e.g., dynamic key fetching).
    • Mitigation: Configure custom rulesets to exclude Halite-related warnings in phpstan.neon:
      includes:
        - vendor/paragonie/halite/extension.neon
      
  • Backward Compatibility (Reaffirmed):

    • Risk: Private method changes (PR #204) could break custom subclasses.
    • Mitigation: Audit existing Laravel wrappers for Halite (if any) and update to use public methods (e.g., seal()/open()).
  • Performance (Unchanged):

    • Argon2id and libsodium remain the primary performance considerations.

Key Questions (Updated)

  1. Static Analysis Adoption:
    • Should PHPStan/Psalm be enforced in CI for Halite-related code (e.g., custom encryption traits)?
  2. Key Normalization:
    • How will Laravel’s config/encryption.php keys be normalized for Halite (e.g., base64 encoding)?
  3. Test Coverage:
    • Should Halite’s expanded tests be integrated into Laravel’s test suite (e.g., via pest.php)?
  4. Audit Logging:
    • Can PHPStan/Psalm detect missing audit logs for cryptographic operations?
  5. Key Rotation:
    • Will the removal of final modifiers enable custom key rotation logic in Laravel?

Integration Approach

Stack Fit (Updated)

  • PHP/Laravel Alignment:

    • Strengths:
      • PHPStan/Psalm integration enables proactive detection of Laravel-specific issues (e.g., incorrect key types in Halite::encrypt()).
      • Expanded test coverage simplifies Laravel integration testing (e.g., mocking Halite in unit tests).
    • Dependencies:
      • Requires PHP 8.1+ and ext-sodium (unchanged).
      • Add PHPStan/Psalm to composer.json for static analysis:
        "require-dev": {
            "phpstan/phpstan": "^1.10",
            "vimeo/psalm": "^6.0"
        }
        
  • Tooling Compatibility (Updated):

    • CI/CD: Add PHPStan/Psalm checks to Laravel’s pipeline:
      # .github/workflows/laravel.yml
      - name: Static Analysis
        run: |
          vendor/bin/phpstan analyse --level=5 app/
          vendor/bin/psalm --init
      
    • IDE Support: Configure PHPStan in Laravel IDE Helper (e.g., phpstan.neon for Halite).

Migration Path (Updated)

  1. Assessment Phase (Reinforced):

    • Run PHPStan/Psalm on existing cryptographic code to identify Halite-specific issues.
    • Example command:
      vendor/bin/phpstan analyse --level=5 app/Http/Controllers/ --focus-on-tests
      
  2. Incremental Rollout (Updated):

    • Phase 1: Replace Crypt::encrypt() with Halite::encrypt() and validate with PHPStan.
    • Phase 2: Implement custom LaravelHalite wrapper (as shown above) and test with Psalm.
    • Phase 3: Integrate Halite’s expanded tests into Laravel’s test suite:
      // tests/Feature/HaliteTest.php
      use ParagonIE\Halite\Tests\HaliteTest as BaseHaliteTest;
      
      class HaliteTest extends BaseHaliteTest {
          protected function setUp(): void {
              $this->halite = new LaravelHalite();
          }
      }
      
  3. Backward Compatibility (Reinforced):

    • Use adapter pattern to wrap Halite for existing EncryptsAttributes:
      trait HaliteEncryptsAttributes {
          public function getAttribute($key) {
              $value = parent::getAttribute($key);
              return LaravelHalite::instance()->unseal($value) ?? $value;
          }
      }
      

Compatibility (Updated)

  • Laravel-Specific Considerations:

    • Static Analysis: Configure PHPStan to ignore Halite’s internal methods:
      # phpstan.neon
      ignoreErrors:
        - "Method ParagonIE\Halite\Halite::privateMethod() is not public."
      
    • Testing: Use Halite’s test suite to validate Laravel integrations:
      // Example test for LaravelHalite
      public function testLaravelHaliteEncryption() {
          $halite = new LaravelHalite();
          $this->assertTrue(HaliteTest::testEncryptDecrypt($halite));
      }
      
    • Key Management: Extend KeyFactory for Laravel’s config/encryption.php:
      class LaravelKeyFactory extends KeyFactory {
          public function getMasterKey(): string {
              return base64_encode(config('encryption.key'));
          }
      }
      
  • Third-Party Packages (Unchanged):

    • No conflicts identified; Halite’s changes are internal.

Sequencing (Updated)

  1. Prerequisites (Updated):

    • Install PHPStan/Psalm and configure for Halite:
      composer require --dev phpstan/phpstan vimeo/psalm
      vendor/bin/phpstan analyse --init
      
    • Add LaravelHalite to config/app.php services:
      'halite' => LaravelHalite::class,
      
  2. Core Integration (Updated):

    • Implement LaravelHalite with static analysis support:
      class LaravelHalite extends Halite {
          public function __construct() {
              parent::__construct(
                  $this->app['config']['halite.key']
              );
          }
      }
      
    • Create a HaliteServiceProvider with PHPStan-validated methods:
      public function register() {
          $this->app->singleton(Halite::class, function () {
              return new LaravelHalite();
          });
      }
      
  3. Feature Rollout (Updated):

    • Week 1: Replace Crypt::encrypt() and validate with PHPStan.
    • Week 2: Implement HaliteEncryptsAttributes trait and test with Psalm.
    • Week 3: Integrate Halite’s test suite and audit static analysis results.

Operational Impact

Maintenance (Updated)

  • Static Analysis:
    • Pros: PHPStan/Psalm catches Laravel-specific issues early (e.g., incorrect key types).
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.
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
atriumphp/atrium