encrypt decrypt javascript

  1. Install a Node.js package that can handle encryption and decryption, such as CryptoJS or Node.js Crypto.

  2. Require the encryption module in your code with the following line: javascript const CryptoJS = require('crypto-js');

  3. Use a strong encryption algorithm and a secret key to encrypt a string, like this: javascript const encryptedMessage = CryptoJS.AES.encrypt('your message', 'your secret key').toString();

  4. To decrypt the message, use the following code: javascript const bytes = CryptoJS.AES.decrypt(encryptedMessage, 'your secret key'); const decryptedMessage = bytes.toString(CryptoJS.enc.Utf8);

  5. Handle the encrypted and decrypted messages based on your application's requirements.

  6. Remember to keep the secret key secure and use proper key management practices for encryption.