CryptoController.js 551 B

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. let AES;
  3. let ENC;
  4. AES = require('crypto-js/aes');
  5. ENC = require('crypto-js/enc-utf8');
  6. const CryptoController = {
  7. encrypt(obj
  8. /*: any*/
  9. , secretKey
  10. /*: string*/
  11. )
  12. /*: ?string*/
  13. {
  14. const encrypted = AES.encrypt(JSON.stringify(obj), secretKey);
  15. return encrypted.toString();
  16. },
  17. decrypt(encryptedText
  18. /*: string*/
  19. , secretKey
  20. /*: string*/
  21. )
  22. /*: ?string*/
  23. {
  24. const decryptedStr = AES.decrypt(encryptedText, secretKey).toString(ENC);
  25. return decryptedStr;
  26. }
  27. };
  28. module.exports = CryptoController;