Reputation: 440
I'm looking to implement the following secure stream using Wowza Engine.
https://www.wowza.com/docs/how-to-protect-streaming-using-securetoken-in-wowza-streaming-engine
In order to do that I need to produce a sha256 hash of a string in python. When I hash my string using sha256 and call hexdigest I get a hex string as the result.
When I call digest I get a byte array. I'm looking to produce the equivalent of this php code.
$hashstr = hash(‘sha256’, ‘live/definst/test.stream?c7800e7e5afc8c0b&wowzatokenendtime=0&wowzatokenstarttime=0’, true);
https://www.php.net/manual/en/function.hash.php
The piece I can't quite figure out is the binary return flag in php. From the docs above:
Returns a string containing the calculated message digest as lowercase hexits unless binary is set to true in which case the raw binary representation of the message digest is returned.
My current code:
import base64
import codecs
import hashlib
from datetime import datetime
base_url = 'rtsp://server.domain.com:1935/'
prefix = 'vodTest/_defaultVHost_/sample.mp4?'
secret = 'SECRET_STRING'
wowza_end_time = '1646394821'
def test():
print(get_rtsp_hash_string())
def get_rtsp_hash_string():
string_to_hash = prefix + '&wowzatokenendtime=' + wowza_end_time + '&' + secret
return base64.b64encode(hashlib.sha256(string_to_hash.encode('utf-8')).digest()).decode()
def get_url():
return base_url + prefix + '?' + 'wowzatokenhash=' + get_rtsp_hash_string()
Any suggestions appreciated?
Thanks,
Shawn
Upvotes: 0
Views: 313