Refactor base64 encoding for serializers.

This refactors the base64-encoding into a common method shared by
all serializers. The serializers now get the value using this new
method and just need to set it somewhere in the params.