Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support to Explicitly Set Secret Before Encrypting/Decrypting #2

Open
ManojBitx opened this issue Oct 29, 2024 · 0 comments
Open

Comments

@ManojBitx
Copy link
Owner

Currently, the encrypter-bundle relies solely on the pre-configured secret defined in the configuration for all encryption and decryption operations. This setup limits flexibility, especially in cases where a temporary or alternative secret needs to be applied for specific encryption/decryption tasks.

Problem Statement: a developer may need to override the default secret for one-time encryption or decryption without altering the globally configured secret in certain scenarios. This lack of flexibility can lead to issues when secure, context-specific encryption flows are required. Currently, the bundle has no mechanism to set a temporary secret before calling the encrypt or decrypt methods.

Proposed Solution:

  1. Temporary Secret Override: Introduce a method (e.g., setTemporarySecret($secret)) that allows the user to specify a one-time secret before invoking the encrypt or decrypt methods. This secret will override the configured secret only for that specific operation.

  2. Reset Method: Add a resetSecret() method to revert to the originally configured secret. This method will be useful to ensure that subsequent operations continue using the default configuration.

Proposed API Changes:

setTemporarySecret($secret): Sets a temporary secret for immediate encryption/decryption.
resetSecret(): Reverts back to the original, configured secret.

$encrypter->setTemporarySecret('temporarySecret123');
$encryptedData = $encrypter->encrypt($data);
$decryptedData = $encrypter->decrypt($encryptedData);

// Reset to the original secret for future operations
$encrypter->resetSecret();

Benefit: This enhancement would provide flexibility to handle different encryption scenarios securely and allow developers to specify an alternate secret when needed, all while ensuring the configured secret remains protected. This functionality would be handy in cases requiring on-demand encryption adjustments without modifying global settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant