encrypt.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Pretend Station Request
  2. import { AESCipher } from '../src/utils/cipher/aes'
  3. import { HmacCipher } from '../src/utils/cipher/hmac'
  4. import { ChargeStationReqEndPointDTO } from '../factory-types/src/dto/chargeStation/endPoint/end.dto'
  5. const aesCipher = new AESCipher()
  6. const hmacCipher = new HmacCipher()
  7. const secret = {
  8. Crazy_Charge_DataSecret: '1ebbf89ffaaff9c6',
  9. Crazy_Charge_DataSecretIV: '8fd9154b6ef6f7c1',
  10. Crazy_Charge_SigSecret: 'a955047992ff5096',
  11. }
  12. const data = {
  13. ConnectorID: 'string',
  14. Status: 0,
  15. ParkStatus: 1,
  16. LockStatus: 1,
  17. }
  18. const encryptData = aesCipher.encrypt(
  19. JSON.stringify(data),
  20. // 'abc',
  21. // 'def'
  22. secret.Crazy_Charge_DataSecret,
  23. secret.Crazy_Charge_DataSecretIV
  24. )
  25. const payload: ChargeStationReqEndPointDTO = {
  26. OperatorID: '192316877',
  27. Data: encryptData,
  28. Seq: '0001',
  29. TimeStamp: '20240628075810',
  30. }
  31. const constructSigText =
  32. payload.OperatorID + payload.Data + payload.TimeStamp + payload.Seq
  33. payload.Sig = hmacCipher.hmacMD5Sign(
  34. constructSigText,
  35. secret.Crazy_Charge_SigSecret
  36. )
  37. console.log(JSON.stringify(payload))