hash.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Created by MyPC on 2019/11/7.
  3. */
  4. var crypto = require('crypto');
  5. //加密
  6. var hashEncode=function (id){//aes192
  7. var cipher = crypto.createCipher('aes192', CRYPTO_KEY);
  8. var enc = cipher.update(id, 'utf8', 'hex');
  9. enc += cipher.final('hex');
  10. return enc;
  11. }
  12. //解密
  13. var hashDecode=function (id){
  14. var decipher = crypto.createDecipher('aes192', CRYPTO_KEY);
  15. var dec = decipher.update(id, 'hex', 'utf8');
  16. dec += decipher.final('utf8');
  17. return dec;
  18. }
  19. //解密
  20. var hashStaffDecode=function (id){
  21. var decipher = crypto.createDecipher('aes-256-ctr', CRYPTO_KEY);
  22. var dec = decipher.update(id, 'hex', 'utf8');
  23. dec += decipher.final('utf8');
  24. return dec;
  25. }
  26. var isNotANumber=function(inputData){
  27. if (isNaN(inputData)) {
  28. return false;
  29. } else {
  30. return true;
  31. }
  32. }
  33. //是否存在或者为空
  34. var isExistence=function (data){
  35. if(Array.isArray(data)){
  36. if(data.length==0){
  37. return false;
  38. }else{
  39. return true;
  40. }
  41. }else if(data==''||data===null||typeof(data) == 'undefined'||data=='undefined'){
  42. return false;
  43. }else{
  44. return true;
  45. }
  46. }
  47. exports.hashDecode = hashDecode;
  48. exports.hashEncode = hashEncode;
  49. exports.hashStaffDecode = hashStaffDecode;
  50. exports.isNotANumber = isNotANumber;
  51. exports.isExistence = isExistence;