Thanks guys, I realise that the javascript function I posted is just shifting the characters and isn't real encryption. All I was looking for was a simple way to mask the data being sent to the server.
I had a quick look for what the ^ operator does in Javascript but couldn't find any info on it. The ^ operator isn't available in Ruby 1.9.3 so I don't know what the Ruby equivalent would look like. Cryptocat looks interesting but I couldn't find any good examples, AES looks like it could work. http://www.movable-type.co.uk/scripts/aes.html Cheers, On Friday, 22 June 2012 23:02:06 UTC+10, Clifford Heath wrote: > > On 22/06/2012, at 5:54 PM, Mark Brown wrote: > > I know trying to secure anything on the client-side is a no-no. > > > > function crypt(text, key) { > > var result = ""; > > for(var i=0, ii=text.length; i<ii; ++i) { > > result += String.fromCharCode(key^text.charCodeAt(i)); > > } > > return result; > > } > > > > crypt('{ data: "yep" }', 6) => "}&bgrg<&$ cv$&{" > > crypt("}&bgrg<&$ cv$&{", 6) => { data: "yep" } > > > > Can anyone help with a Ruby equivalent? to decrypt that string? > > Or does anyone have other examples of client-side encryption and > decryption in Ruby? > > That code doesn't do encryption - it's just a byte-wise xor mask. > The Ruby equivalent is trivial. > > In regard to encryption on the client side, the client should be regarded > as an untrusted third party. It must prove its authenticity in *every* > transaction, > by a signature applied over the entire message content. The signature may > be constructed using a shared secret or by use of a private key. > > Clifford Heath. -- You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group. To view this discussion on the web visit https://groups.google.com/d/msg/rails-oceania/-/pJMXcWw0LQUJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en.
