CryptoController.js 519 B

1234567891011121314151617
  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 /*: any*/, secretKey /*: string*/) /*: ?string*/{
  8. const encrypted = AES.encrypt(JSON.stringify(obj), secretKey);
  9. return encrypted.toString();
  10. },
  11. decrypt(encryptedText /*: string*/, secretKey /*: string*/) /*: ?string*/{
  12. const decryptedStr = AES.decrypt(encryptedText, secretKey).toString(ENC);
  13. return decryptedStr;
  14. }
  15. };
  16. module.exports = CryptoController;