# 验签

## MD5 验签

按 生成MD5签名的方式，对响应数据进行MD5计算，然后将计算结果与响应中的 sign 进行比较，一致代表数据未被篡改，可以信任，否则忽略

### MD5 验签示例

{% tabs %}
{% tab title="Node.js" %}

```
function verifyMD5(response) {
  const data = Object.keys(response)
    .sort()
    .reduce((obj, key) => {
      obj[key] = response[key]
      return obj
    }, {})
  var str = ''
  Object.keys(data).forEach((key) => {
    if (data[key] != '' && key != 'sign') {
      str = str + key + '=' + data[key] + '&'
    }
  })
  str = str + 'pkey=' + YOUR_MD5_SECRET_KEY
  return md5(str) == response['sign']
}
```

{% endtab %}

{% tab title="PHP" %}

```
```

{% endtab %}

{% tab title="Java" %}

```
```

{% endtab %}
{% endtabs %}

## RSA 验签签名

RSA验证签名需要按 RSA签名生成规则 对 response 生成 URL key-value 格式的字符串, 然后使用 UseePay RSA 公钥进行签名验证

{% tabs %}
{% tab title="Node.js" %}

```
function verifyRSA(response) {
  const data = Object.keys(response)
    .sort()
    .reduce((obj, key) => {
      obj[key] = response[key]
      return obj
    }, {})
  var str = ''
  Object.keys(data).forEach((key) => {
    if (data[key] != '' && key != 'sign') {
      str = str + key + '=' + data[key] + '&'
    }
  })
  var result = new NodeRSA(USEEPAY_RSA_PUBLICK_KEY, 'pkcs8-public').verify(
    Buffer.from(str),
    response['sign'],
    'base64',
    'base64',
  )
  return result
}
```

{% endtab %}

{% tab title="PHP" %}

```
```

{% endtab %}

{% tab title="Java" %}

```
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://useepay.gitbook.io/developer/guide/signature-guide/signature-verification.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
