Encrypt & Decrypt text in Ruby

If you want to pass some information to a client that you don't want the client to read or temper with, read on!

The usage of our TextEncryptor is straightforward:

data = { ... }
serialized_data = JSON.dump(data)
encoded_data = TextEncryptor.encrypt(serialized_data)

# ...

serialized_data = TextEncryptor.decrypt(encoded_data)
data = JSON.parse(serialized_data)


One of the ways I use this is to store a proof that a phone number is verified on client side and allow exchanging that encoded phone number token to login or signup. You can read more about this in one of the following blog posts.

Thank you for reading!

Popular posts from this blog

Next.js: restrict pages to authenticated users

HTTP server in Ruby 3 - Fibers & Ractors

Using image loader is Next.js