View Source Elixir bindings for libsrtp

Hex.pm API Docs CircleCI

Installation

The package can be installed by adding :ex_libsrtp to your list of dependencies in mix.exs:

def deps do
  [
    {:ex_libsrtp, "~> 0.7.2"}
  ]
end

This package is based on libsrtp. The precompiled builds will be pulled and linked automatically. However, should there be any problems, consider installing it manually.

Manual instalation of dependencies

macOS

brew install srtp

Ubuntu

apt install libsrtp2-dev

Arch/Manjaro

pacman -S libsrtp

Usage

This library allows to convert RTP to SRTP and the other way round. The following snippet shows how to encrypt and decrypt a packet:

iex> in_srtp = ExLibSRTP.new()
iex> ExLibSRTP.add_stream(in_srtp, %ExLibSRTP.Policy{ssrc: :any_inbound, key: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"})
:ok
iex> packet = <<128, 14, 15, 143, 98, 145, 127, 247, 233, 164, 145, 140, 1, 2, 3, 4>>
iex> {:ok, protected_packet} = ExLibSRTP.protect(in_srtp, packet)
{:ok,
 <<128, 14, 15, 143, 98, 145, 127, 247, 233, 164, 145, 140, 112, 112, 222, 241, 148, 205, 10, 185, 78, 20, 27, 103, 2, 207>>}
iex> out_srtp = ExLibSRTP.new()
iex> ExLibSRTP.add_stream(out_srtp, %ExLibSRTP.Policy{ssrc: :any_outbound, key: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"})
:ok
iex> {:ok, unprotected_packet} = ExLibSRTP.unprotect(out_srtp, protected_packet)
{:ok, <<128, 14, 15, 143, 98, 145, 127, 247, 233, 164, 145, 140, 1, 2, 3, 4>>}
iex> unprotected_packet == packet
true

Copyright 2020, Software Mansion

Software Mansion

Licensed under the Apache License, Version 2.0