Wowza outgoing security Secure Token and PHP, Android client

on

Configure outgoing security using Wowza Streaming Engine Manager

There is a very good documentation in Wowza forum to enable security token for Wowza steaming server.

Here is link to follow:

http://www.wowza.com/forums/content.php?578-How-to-configure-security-using-Wowza-Streaming-Engine-Manager

Now the outgoing stream is secured. If any one knows the secret token, then only generate the authenticate URL for steaming.

Here are some code example to do this.

Connect with Wowza output steam when SHA-256 security token applied:

With PHP:

<?php
date_default_timezone_set('Asia/Dhaka');//set the time zone if server time-zone is not correct
$wowza_serverip = "103.248.14.30"; //your ip/host
$wowzatoken = 'wowzatoken';

$wowzastart = 0;
$validity = 1800; //validity in seconds
$wowzaend = strtotime(date('d-m-Y H:i')) + $validity;
$secret = "7a97766ef659050"; //your secret key
$stream_name = "live/myStream";//your stream-myStream is default steaming

$hashstr = hash('sha256', $stream_name.'?'.$secret.'&amp;amp;'.$wowzatoken.'endtime='.$wowzaend.'&amp;amp;'.$wowzatoken.'starttime='.$wowzastart.'', true);
$usableHash = strtr(base64_encode($hashstr), '+/', '-_');

//RTMP protocol usable for Flash Player and Android
$url = "rtmp://".$wowza_serverip.":1935/live/myStream?".$wowzatoken."endtime=".$wowzaend."&amp;amp;".$wowzatoken."starttime=".$wowzastart."&amp;amp;".$wowzatoken."hash=".$usableHash."";
//HLS protocol for iPhone
$iurl = $wowza_serverip.":1935/live/myStream/playlist.m3u8?".$wowzatoken."endtime=".$wowzaend."&amp;amp;".$wowzatoken."starttime=".$wowzastart."&amp;amp;".$wowzatoken."hash=".$usableHash."";
?>

With Android:

VideoView vidView = (VideoView) playListView.findViewById(R.id.myVideo);

String wowza_serverip = "http://103.239.254.66"; //your ip/host
String wowzatoken = "wowzatoken";

Long wowzastart = 0l;
int validity = 1800; // validity in seconds
Long wowzaend = new Date().getTime() + validity;

String secret = "7a97766ef659050"; // your secret
String stream_name = "live/myStream";// your stream myStream is default steaming

MessageDigest md;
String hashstr;
String usableHash = null;
byte[] digest;

hashstr = stream_name + "?" + secret + "&amp;amp;" + wowzatoken + "endtime=" + wowzaend + "&amp;amp;" + wowzatoken + "starttime="+wowzastart;

Log.i(TAG, "Hashable Str : " + hashstr);
try {
    md = MessageDigest.getInstance("SHA-256");
    md.update(hashstr.getBytes("UTF-8")); // Change this to "UTF-16" if needed
    digest = md.digest();
    hashstr = new String(Base64.encodeToString(digest, Base64.DEFAULT));
    usableHash = hashstr.replace('+', '-').replace('/', '_');
    Log.i(TAG, "HashCode : " + usableHash);
} catch (Exception e) {
    e.printStackTrace();
}
String iurl = wowza_serverip + ":1935/live/myStream/playlist.m3u8?"+
    wowzatoken + "endtime="+ String.valueOf(wowzaend) + "&amp;amp;" +
    wowzatoken + "starttime=" + String.valueOf(wowzastart) + "&amp;amp;" +
    wowzatoken + "hash=" + usableHash;

Log.i(TAG, "Live URL = " + iurl);
Uri vidUri = Uri.parse(iurl);
vidView.setVideoURI(vidUri);

Leave a Reply

Your email address will not be published. Required fields are marked *