Token Mechanism
A token is constructed as:
{timestamp}-{signature}
timestamp
: Unix timestamp in secondssignature
: MD5 of/{app}/{stream}-{timestamp}-{key}
Steps:
- Concatenate the string to be encrypted using the following format:
"/" + {app} + "/" + {stream} + "-" + {timestamp} + "-" + {key}
- Use the MD5 algorithm to the concatenated string to generate the signature.
- Form the token using the timestamp, hyphen and signature.
Example pseudocode:
private String md5Sum(String src) {
MessageDigest md5 = null;
try {
md5 = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
md5.update(StandardCharsets.UTF_8.encode(src));
return String.format("%032x", new BigInteger(1, md5.digest()));
}
private String generateToken() {
String key = "your key"; //secret key
String app = "your app name"; //app name
String stream = "your stream name"; //stream name
long timestamp = 1730102840; //unix timestamp, seconds
String toEncryptStr = String.format("/%s/%s-%s-%s", app, stream, timestamp, key);
String signature = md5Sum(toEncryptStr);
String token = String.format("%s-%s", timestamp , signature);
return token;
} - Form RTMP ingest URL
The RTMP ingest URL is composed of the schema, ingest domain, app, stream name, and query parameters (including the token). Format:rtmp://{ingest_domain}/{app}/{stream}?token={token}&{custom_parameters}=...