forked from Softvelum/paywall-code-samples-wmsauth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
31 lines (26 loc) · 1.37 KB
/
Copy pathMain.java
File metadata and controls
31 lines (26 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import java.io.UnsupportedEncodingException;
import java.util.Locale;
public class Main {
public static void main(String[] args) throws UnsupportedEncodingException {
DateTimeFormatter timeFormatter = DateTimeFormat.forPattern("M/d/y h:m:s a").withZone(DateTimeZone.UTC).withLocale(Locale.US);
DateTime currentServerTime = new DateTime(DateTimeZone.UTC); // lets get localtime in UTC timezone
String today = timeFormatter.print(currentServerTime);
String video_url = "http://yourdomain.com:8081/live/Stream1";
String ip = "127.0.0.1";
String key = "defaultpassword";
String validminutes = "20";
String to_hash = ip + key + today + validminutes;
byte[] ascii_to_hash = to_hash.getBytes("UTF-8");
String base64hash = Base64.encodeBase64String(DigestUtils.md5(ascii_to_hash));
String urlsignature = "server_time=" + today + "&hash_value=" + base64hash + "&validminutes=" + validminutes;
String base64urlsignature = Base64.encodeBase64String(urlsignature.getBytes("UTF-8"));
String signedurlwithvalidinterval = video_url + "?wmsAuthSign=" + base64urlsignature;
return;
}
}