feat: add encrypt and decrypt functions #679
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #678
It is useful for
data-attributes
and server actions, but can be used also for API endpoints, etc...We already had the methods because they were in the encrypted store, but they were not exposed and it does not cost anything, as they are useful.
encrypt
Reference
encrypt(textOrObject: unknown): string
The
encrypt
function allows you to securely send sensitive data from the client to the server. It is typically used in conjunction with thedecrypt
function to safely handle data transmission.Converts a given text or object into an encrypted string for secure client-server communication.
Example usage:
In this example, the
encrypt
function secures the data before it is stored in adata-encrypted
attribute. Thedecrypt
function is then used on the server to recover the original value.decrypt
Reference
decrypt(encryptedString: string): unknown
The
decrypt
function allows you to securely retrieve sensitive data sent from the client to the server. It works in conjunction with theencrypt
function to ensure safe handling of sensitive information.Converts an encrypted string back into its original text or object, enabling secure client-server communication.
Example usage:
In this example, the
encrypt
function secures the data before it is stored in adata-encrypted
attribute. Thedecrypt
function is then used on the server to recover the original value.