title: Rails Base64 decoding
body: <p>I have to implement a client and server for end-to-end encryption. </p>
  
  <p>So if I am correctly informed, I need to encode and decode my keys with Base64.</p>
  
  <blockquote>
    <p>ArgumentError (string contains null byte):
     app/controllers/users_controller.rb:46:in `register'</p>
  </blockquote>
  
  <p>This is what I get just after the request reached my Server. </p>
  
  <p>And that is the code i have written. </p>
  
  <pre><code>43 tempkey = Base64.decode64(params[:privkey_user_enc])
  44    @user = User.new(:identity =&gt; params[:identity], :salt_masterkey =&gt; params[:salt_masterkey], :pubkey_user =&gt; params[:pubkey_user], :privkey_user_enc =&gt; tempkey)
  45      if !(User.find_by_identity(@user.identity))
  46          if @user.save
  </code></pre>
  
  <p>And a snippet from the key:</p>
  
  <blockquote>
    <p>LSFzoeT/7VLtWCQHEx3p3Nz3AfC7toACKRWELNC5E6CtSEsp6pZ7b4zldP\n2J5otJjjGSmVgg7e8XtndpAoI6ZJdBr/XeMoKNID9bs1kiWw2BAOduTWJ37a\nBAurnBZlOGycwvRXPmSDbMLSEyuCf53UTpskIhCkLDv21rW2qklIVC22Z+k6\n3dSRYZ5dQjPwhdfkaUgXwcRQFMazbdw/RSSNH0twcax7msHZms2iVlgvjElN\n+qi5Iu77J3DZCOE2fAo06WXALQfG2gOuzTWwlsVOW+iwj/tMypYzEAu+Y+kx\n51M0XlwRgAyRSqg7MMyT8OGC/jtJgc1A8gwSn7pz9cSnTCFUFh1eulE4pLpS\n4Gxm30aqHPCpNgvjJssNdntbdMxn10mfg7wzJNvSeFof90rSZb+PNWwvlYBZ\nQLjB1J9myQwq1+ptzvcgeskaRaGBWpSXyeo2HUCcsRNbajqjSViyheKKMWDb\n7H6tdlrIE+d1XcwIvczU9DbgtIB8gy8PBL6XI5KLSq9gzy/TSVahCeqURyA4\nnmT2luNxdggQLc7aY0aL03vNl5dun0Xem2rVCI3lFo2e4WH</p>
  </blockquote>
  
  <p>I think I may have narrowed the problem down to <code>tempkey</code> but I am not quite sure.</p>
  
  <p>I would really appreciate any help. I found nothing in the Internet that solved my problem.</p>
  
  <p>Thanks.</p>