cipher.js 602 B

1234567891011121314151617181920212223
  1. /**
  2. * Created by zhang on 2019/5/10.
  3. */
  4. let crypto = require('crypto');
  5. module.exports ={
  6. aesEncrypt:aesEncrypt,
  7. aesDecrypt:aesDecrypt
  8. };
  9. function aesEncrypt(data, key = 'SmartCost') {
  10. const cipher = crypto.createCipher('aes192', key);
  11. var crypted = cipher.update(data, 'utf8', 'hex');
  12. crypted += cipher.final('hex');
  13. return crypted;
  14. }
  15. function aesDecrypt(encrypted, key= 'SmartCost') {
  16. const decipher = crypto.createDecipher('aes192', key);
  17. var decrypted = decipher.update(encrypted, 'hex', 'utf8');
  18. decrypted += decipher.final('utf8');
  19. return decrypted;
  20. }