templatized rsa encode/decode