Encryption work with public gallery

Make encryption work with the public gallery.

should fix #5948 @PVince81 please test it, thanks!