-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add encrypt and decrypt functions (#679)
- Loading branch information
Showing
8 changed files
with
210 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
description: The `encrypt` function allows you to securely send sensitive data from the client to the server | ||
--- | ||
|
||
# `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 the [`encrypt`](/api-reference/server-apis/encrypt) 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: | ||
|
||
```tsx 8 | ||
import { encrypt, decrypt } from "brisa/server"; | ||
|
||
// ... | ||
<button | ||
onClick={(e: Event) => { | ||
// Decrypt on the server action: | ||
console.log( | ||
decrypt((e.target as HTMLButtonElement).dataset.encrypted!) | ||
) | ||
}} | ||
data-encrypted={encrypt("some sensible data")} | ||
> | ||
Click to recover sensible data on the server | ||
</button> | ||
``` | ||
|
||
In this example, the [`encrypt`](/api-reference/server-apis/encrypt) function secures the data before it is stored in a `data-encrypted` attribute. The `decrypt` function is then used on the server to recover the original value. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
description: The `encrypt` function allows you to securely send sensitive data from the client to the server | ||
--- | ||
|
||
# `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 the [`decrypt`](/api-reference/server-apis/decrypt) function to safely handle data transmission. | ||
|
||
Converts a given text or object into an encrypted string for secure client-server communication. | ||
|
||
## Example usage: | ||
|
||
```tsx 11 | ||
import { encrypt, decrypt } from "brisa/server"; | ||
|
||
// ... | ||
<button | ||
onClick={(e: Event) => { | ||
// Decrypt on the server action: | ||
console.log( | ||
decrypt((e.target as HTMLButtonElement).dataset.encrypted!) | ||
) | ||
}} | ||
data-encrypted={encrypt("some sensible data")} | ||
> | ||
Click to recover sensible data on the server | ||
</button> | ||
``` | ||
|
||
In this example, the `encrypt` function secures the data before it is stored in a `data-encrypted` attribute. The [`decrypt`](/api-reference/server-apis/decrypt) function is then used on the server to recover the original value. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters