Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Base64 encoding in Ruby on Rails?

I'm working in Base64 in Ruby on Rails and have a question:

For example how would the following be Base64 encoded / decoded?

<a href="myroute?id=<%[email protected]%>"> MY LINK</a>
like image 506
pedroooo Avatar asked Jan 14 '15 16:01

pedroooo


1 Answers

To create Base64 try this:

def create_base_64 
  begin 
    #for create 
    a = 1
    b = Base64.encode64(a.to_s)
    # for decoding
    c = Base64.decode64(b)
    puts c
  rescue Exception => e 
    puts e 
  end 
end

For more security try to broke it. For example:

b[1] = b[1] << SecureRandom.hex(1)

And other action, you recived the param b:

b = params[:b]
b[2]=""
b[2]=""
c = base64.decode64(b.to_s)
like image 70
Luis Avatar answered Sep 21 '22 11:09

Luis