Most of the time we prefer people to use Metasploit API to easier maintain it.  In this case, can you use Rex::Text.encode_base64() instead?