API signature

Signature verification

ฝั่งที่รับข้อมูลต้องทำการตรวจสอบความถูกต้องและความปลอดภัยของข้อมูล ซึ่งจะส่งผ่าน header ที่มีชื่อว่า x-casino-signature โดยจะต้องใช้ authentication key ในการตรวจสอบ สามารถดูตัวอย่างโค้ดได้ตามข้างล่างนี้

String authenticationKey = '...'; // authentication key string
String httpRequestBody = '...'; // Request body string
SecretKeySpec key = new SecretKeySpec(authenticationKey.getBytes(), "HmacSHA256");
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(key);
byte[] source = httpRequestBody.getBytes("UTF-8");
String signature = Base64.encodeBase64String(mac.doFinal(source));
// Compare x-signature-signature request header string and the signature

Signature generation

ฝั่งที่ส่งข้อมูลต้องทำการสร้าง x-casino-signature แล้วส่งผ่าน header เพื่อให้ฝั่งรับใช้สำหรับตรวจสอบความถูกต้องและความปลอดภัยของข้อมูล

String authenticationKey = '...'; // authentication key string
String httpRequestBody = '...'; // Request body string
SecretKeySpec key = new SecretKeySpec(authenticationKey.getBytes(), "HmacSHA256");
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(key);
byte[] source = httpRequestBody.getBytes("UTF-8");
String signature = Base64.encodeBase64String(mac.doFinal(source));

Last updated