Fix encrypt issue

see #276

Adding test and fix ssl issue