Fixed connection encryption.

Fixes #975.