Polyv Help Center

Help Center

MD5/SHA256 Signature Generation Rules

Updated: 2026-09-18 11:33:51

The sub-account module of the VOD system and the retrieval of video playback credentials use the MD5 signature rule by default, and also support specifying the SHA256 signature rule via the request parameter signatureMethod=SHA256; most other VOD modules use the SHA1 signature rule, as detailed below:

  1. Obtain the signature key information for the sub-account appid and secretkey. Log in to the official website -> select any VOD function -> Settings -> Account Management -> select the sub-account modification function (if there is no sub-account, add a sub-account), as follows:

Note: Only sub-accounts with the content distribution role have appid and secretkey.

image-20210406142532279

image-20210414162813703

image-20210414163119453

  1. Use the MD5 signature algorithm to generate the signature. The specific encryption calculation method is as follows:

  2.1 Arrange the required request parameters (parameters with non-null values) in dictionary order by parameter name, concatenating the parameter name and parameter value. For example: ts1552447784505userIde6b23c6f51videoIde6b23c6f51c4b1cb9f0302a92ed42440_eviewerIdabcd1234viewerIp127.0.0.1;

  2.2 Add the secretKey to the beginning and end of the concatenated string. Taking secretKey as abc as an example, you get: abcts1552447784505userIde6b23c6f51videoIde6b23c6f51c4b1cb9f0302a92ed42440_eviewerIdabcd1234viewerIp127.0.0.1abc

  2.3 Then calculate MD5 using UTF-8 encoding, and convert the MD5 result to uppercase letters as the sign.

Common issues:

  1. Parameters with null values are not excluded during string concatenation.

  2. The character set used for signing must be UTF-8. If not specified, the platform's default character set may be used, leading to errors.


Others

SHA256 Signature Algorithm (Optional)

This platform also supports the SHA256 signature algorithm for calculating signatures. The specific encryption calculation method is as follows:

  1. Specify the request parameter signatureMethod=SHA256. If this parameter is absent, MD5 signature is used by default.
  2. Arrange the request parameters (parameters with non-null values) in ascending order by key (parameter name) in dictionary order (ASCII value).
  3. Concatenate the parameter names and values into key1value1key2value2...keyNvalueN.
  4. Add the secretKey to the beginning and end of the concatenated string.
  5. Calculate SHA256 on the concatenated string using UTF-8 encoding, and convert the SHA256 result to uppercase letters as the sign.

For quick integration of basic code, please download the relevant dependency source code. Click here to download the source code. After downloading, add it to your own source project. The test cases include HttpUtil.java and VodSignUtil.java in the downloaded file.

It is strongly recommended that you use the VOD Java SDK to complete API function integration. The VOD Java SDK provides unified encapsulation and optimization for API call logic, exception handling, data signing, and HTTP request thread pools.

package net.polyv.common;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.polyv.util.VodSignUtil;


/**
 * @author: thomas
 **/
public class VodSignTest {
    
    private static final Logger log = LoggerFactory.getLogger(VodSignTest.class);
    
    @Test
    public void buildSubSign() throws UnsupportedEncodingException, NoSuchAlgorithmException {
        String appid = "XXXXXXXX";
        String secretkey = "XXXXXXXXXXXXXXXXXXXXXXXX";
        
        long timestamp = System.currentTimeMillis();
        Map<String, String> paramMap = new HashMap<String, String>();
        //公共参数
        paramMap.put("appId", appid);
        paramMap.put("timestamp", Long.toString(timestamp));
        //业务参数
        paramMap.put("vid","1b448be3233659acf35d430ba9210bd4_1");
        
        String sign = VodSignUtil.getSignMd5(paramMap, secretkey);
        log.debug("生成签名:{}",sign);
        
    }

    @Test
    public void buildSubSHA256Sign() throws UnsupportedEncodingException, NoSuchAlgorithmException {
        String appid = "XXXXXXXX";
        String secretkey = "XXXXXXXXXXXXXXXXXXXXXXXX";

        long timestamp = System.currentTimeMillis();
        Map<String, String> paramMap = new HashMap<String, String>();
        //公共参数
        paramMap.put("appId", appid);
        paramMap.put("timestamp", Long.toString(timestamp));
        paramMap.put("signatureMethod", "SHA256");
        //业务参数
        paramMap.put("vid","1b448be3233659acf35d430ba9210bd4_1");

        String sign = VodSignUtil.getSHA256Sign(paramMap, secretkey);
        log.debug("生成SHA256签名:{}",sign);
    }
}


联系客服,在线咨询
在线咨询