Support TLS, dynamic listeners and encrypted storage

You can probably consolidate random generation into one function (see line `97` as well) and then you can just call that function whenever you need random either for a nonce or key since they are both essentially the same thing.