using System.Security.Cryptography;
using System.Collections.Generic;
public static void Main()
var orderObj = new Order();
orderObj.typeofdata ="RENEW";
var customerinfo = new Custimerinfo();
customerinfo.citizen = "z6hhrcGV7yJz7D8n9xv+RQ==";
customerinfo.title = "นาย";
customerinfo.firstname = "apnu/BQkoC+xOeZSLaS/7q++ylMmG5ZqcKENe8B0g+E=";
customerinfo.lastname ="Cl9KIRshb1a2UWUk2kvPyOykBEeEhIRuU5vPfKTFxwyY2+Mr5w5DPa8qEnix1JuX";
customerinfo.gender = "Male";
customerinfo.tel = "S9fzKHRy0ve5Z2R1aGW+pA==";
customerinfo.email = "acB7K8mDqHmMxvIKNQXgGg==";
customerinfo.nationality = "ไทย";
customerinfo.birthdate = "1991-10-17";
var customeraddressObj1 = new Customeraddress();
customeraddressObj1.addresstypecode = "01";
customeraddressObj1.addresno = "428";
customeraddressObj1.moo = "";
customeraddressObj1.buildingname = "อาคารอารีย์ ฮิลล์ ชั้น 15";
customeraddressObj1.alley = "";
customeraddressObj1.road = "พหลโยธิน";
customeraddressObj1.district = "เขตพญาไท";
customeraddressObj1.subdistrict = "สามเสนใน";
customeraddressObj1.province = "กรุงเทพมหานคร";
customeraddressObj1.zipcode = "10400";
customeraddressObj1.countryname = "ไทย";
var customeraddressObj2 = new Customeraddress();
customeraddressObj2.addresstypecode = "02";
customeraddressObj2.addresno = "428";
customeraddressObj2.moo = "";
customeraddressObj2.buildingname = "อาคารอารีย์ ฮิลล์ ชั้น 15";
customeraddressObj2.alley = "";
customeraddressObj2.road = "พหลโยธิน";
customeraddressObj2.district = "เขตพญาไท";
customeraddressObj2.subdistrict = "สามเสนใน";
customeraddressObj2.province = "กรุงเทพมหานคร";
customeraddressObj2.zipcode = "10400";
customeraddressObj2.countryname = "ไทย";
customerinfo.customeraddress = new List<Customeraddress>();
customerinfo.customeraddress.Add(customeraddressObj1);
customerinfo.customeraddress.Add(customeraddressObj2);
var carinfo = new Carinfo();
carinfo.carbrand= "Honda";
carinfo.classicnumber= "AAAAAA12A1A123456";
carinfo.licenseno= "1กข 1234";
carinfo.registrationprovince= "กรุงเทพมหานคร";
carinfo.registrationyear= "2021";
carinfo.carmodel= "City";
var detail = new Detail();
detail.cartypename= "เก๋ง";
detail.typeofusedetail= "ส่วนบุคคล";
detail.cmicartyperoryor= "ร.ย.1";
detail.cmisubcartypecode= "1.10";
detail.cmisubcartypedetail= "";
detail.cmicartypecode= "01";
orderObj.customerinfo=customerinfo;
orderObj.carinfo = carinfo;
orderObj.details = detail;
var dataString = JsonConvert.SerializeObject(orderObj);
Console.WriteLine(dataString);
Console.WriteLine(string.Format("Encrypt: {0}",HmacSHA256("CMIWHITELABELTESTENVIRONMENTNTLL", dataString)));
public static string HmacSHA256(string key, string data)
ASCIIEncoding encoder = new ASCIIEncoding();
Byte[] code = encoder.GetBytes(key);
UTF8Encoding en = new UTF8Encoding();
using (HMACSHA256 hmac = new HMACSHA256(code))
Byte[] hmBytes = hmac.ComputeHash(en.GetBytes(data));
hash = Convert.ToBase64String(hmBytes);
public static string ToHexString(byte[] array)
StringBuilder hex = new StringBuilder(array.Length * 2);
foreach (byte b in array)
hex.AppendFormat("{0:x2}", b);
public string carbrand { get; set; }
public string classicnumber { get; set; }
public string licenseno { get; set; }
public string registrationprovince { get; set; }
public string registrationyear { get; set; }
public string carmodel { get; set; }
public string carcolor { get; set; }
public class Customeraddress
public string addresstypecode { get; set; }
public string addresno { get; set; }
public string moo { get; set; }
public string buildingname { get; set; }
public string alley { get; set; }
public string road { get; set; }
public string district { get; set; }
public string subdistrict { get; set; }
public string province { get; set; }
public string zipcode { get; set; }
public string countryname { get; set; }
public string cartype { get; set; }
public string cartypename { get; set; }
public string typeofusedetail { get; set; }
public string cmicartyperoryor { get; set; }
public string cmisubcartypecode { get; set; }
public string cmisubcartypedetail { get; set; }
public string cmicartypecode { get; set; }
public class Custimerinfo
public string citizen { get; set; }
public string title { get; set; }
public string firstname { get; set; }
public string lastname { get; set; }
public string gender { get; set; }
public string tel { get; set; }
public string email { get; set; }
public string nationality { get; set; }
public string birthdate { get; set; }
public List<Customeraddress> customeraddress { get; set; }
public string typeofdata { get; set; }
public Custimerinfo customerinfo {get;set;}
public Carinfo carinfo { get; set; }
public Detail details { get; set; }