Skip to content

Instantly share code, notes, and snippets.

@saashqdev
Created December 3, 2025 00:35
Show Gist options
  • Select an option

  • Save saashqdev/4358b21269154e2cc182f66165d7c238 to your computer and use it in GitHub Desktop.

Select an option

Save saashqdev/4358b21269154e2cc182f66165d7c238 to your computer and use it in GitHub Desktop.
NextRock crypto algorithm
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