CoTURN: How to use TURN REST API?

前端 未结 6 743
不知归路
不知归路 2020-12-02 18:57

I have build coturn and run it successfully. ip:192.168.1.111. Now the question I faced is to get the Turn credential through REST API. http://tools.ietf.org/html/draft-ube

6条回答
  •  旧巷少年郎
    2020-12-02 19:12

    Here is my c# implementation with TTL

    public string[] GenerateTurnPassword(string username)
    {
        long ttl = 3600 * 6;
        var time = DateTimeOffset.Now.ToUnixTimeSeconds() + ttl;
        var newuser = time + ":" + username;
        byte[] key = Encoding.UTF8.GetBytes("YOURSECRET");
        HMACSHA1 hmacsha1 = new HMACSHA1(key);
        byte[] buffer = Encoding.UTF8.GetBytes(newuser);
        MemoryStream stream = new MemoryStream(buffer);
        var hashValue = hmacsha1.ComputeHash(stream);
        string[] arr = new string[2];
        arr[0] = Convert.ToBase64String(hashValue);
        arr[1] = newuser;
        return arr;
    }
    
    

提交回复
热议问题