Created
December 3, 2025 00:35
-
-
Save saashqdev/4358b21269154e2cc182f66165d7c238 to your computer and use it in GitHub Desktop.
NextRock crypto algorithm
This file contains hidden or 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
| import CryptoJS from "crypto-js"; | |
| function encrypt(text: string) { | |
| const secret = process.env.CRYPTO_SECRET?.toString(); | |
| if (!secret) { | |
| throw Error("CRYPTO_SECRET not set"); | |
| } | |
| const ciphertext = CryptoJS.AES.encrypt(text, secret).toString(); | |
| return ciphertext; | |
| } | |
| function decrypt(ciphertext: string) { | |
| const secret = process.env.CRYPTO_SECRET?.toString(); | |
| if (!secret) { | |
| throw Error("CRYPTO_SECRET not set"); | |
| } | |
| const bytes = CryptoJS.AES.decrypt(ciphertext, secret); | |
| const originalText = bytes.toString(CryptoJS.enc.Utf8); | |
| return originalText; | |
| } | |
| export default { | |
| encrypt, | |
| decrypt, | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment