
# 如何对录制回调进行鉴权？
为保证录制回调通信安全，租户可以配置录制回调参数"回调秘钥"，对录制回调消息进行鉴权。本章节介绍录制回调鉴权签名的生成方法。
#### 参数说明
表1参数说明 
| 参数              | 说明             |
|:---|:---|
| X-Rtc-Rand      | 消息请求头中的随机数。    |
| X-Rtc-Timestamp | 消息请求头中的时间戳。    |
| X-Rtc-Signature | 消息请求头中的签名。     |
| msg             | 消息请求中body体的内容。 |
   
#### 生成录制回调鉴权签名的方法
1. 将如下参数拼接为一个字符串。 代码如下所示：
   ```
   String content = X-Rtc-Rand + X-Rtc-Timestamp + msg;
   ```
   
2. 使用录制回调配置里面的回调秘玥"key"，通过HMAC-SHA256方式，加密拼接的字符串"content"，得到签名字符串。 代码如下所示：
   ```
   String key = System.getenv("KEY");
       String signatureStr = hmacSha(key, content, "HmacSHA256");
       static String hmacSha(String KEY, String VALUE, String SHA_TYPE) {
           try {
               SecretKeySpec signingKey = new SecretKeySpec(KEY.getBytes("UTF-8"), SHA_TYPE);
               Mac mac = Mac.getInstance(SHA_TYPE);
               mac.init(signingKey);
               byte[] rawHmac = mac.doFinal(VALUE.getBytes("UTF-8"));
               byte[] hexArray = {
                       (byte) '0', (byte) '1', (byte) '2', (byte) '3',
                       (byte) '4', (byte) '5', (byte) '6', (byte) '7',
                       (byte) '8', (byte) '9', (byte) 'a', (byte) 'b',
                       (byte) 'c', (byte) 'd', (byte) 'e', (byte) 'f'
               };
               byte[] hexChars = new byte[rawHmac.length * 2];
               for (int j = 0; j < rawHmac.length; j++) {
                   int v = rawHmac[j] & 0xFF;
                   hexChars[j * 2] = hexArray[v >>> 4];
                   hexChars[j * 2 + 1] = hexArray[v & 0x0F];
               }
               return new String(hexChars);
           } catch (Exception ex) {
               throw new RuntimeException(ex);
           }
       }
   ```
   
 
