Q&A

Signature validation is failing when emoji is present in a message

We are trying to compare the x-line-signature with the signature that we generate from the request body and the channel secret, we followed the same code mentioned here in the Line documentation https://developers.line.biz/en/reference/messaging-api/#response for the signature validation. This validation logic works fine for plain text messages but not when an emoji is present in the message.

Now coming to the issue itself, whenever a message includes a emoji, the signature validation is not matching the x-line-signaturesent in the header.We are following the signature validation code mentioned in the documentation here: https://developers.line.biz/en/reference/messaging-api/#signature-validation

Here is the code snippet that we used from the above doc:

String channelSecret = '...'; // Channel secret string
String httpRequestBody = '...'; // Request body string
SecretKeySpec key = new SecretKeySpec(channelSecret.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-line-signature request header string and the signature

Example httpRequestBody that we receive from the webhook:

'{"destination":"****","events":[{"type":"message","message":{"type":"text","id":"14321245792720","text":"😂"},"timestamp":1625166863147,"source":{"type":"user","userId":"****"},"replyToken":"****","mode":"active"}]}'

The signature validation only fails when an emoji is present in an message, for plain text message the signature validation works fine.

  • 0
  • 0
  • 271
  • twitter facebook
本当によろしいですか? question.vm