I saw a while ago the possibility to decrypt and encrypt strings in rails without including any library, but I can\'t find the blog post.
I want to be able to encrypt an
You mean this one?: ActiveSupport::MessageEncryptor. Here is the way to reuse Rails 4 application's secret:
crypt = ActiveSupport::MessageEncryptor.new(Rails.application.secrets.secret_key_base)
encrypted_data = crypt.encrypt_and_sign('my confidental data')
And encrypted data can be decrypted with:
decrypted_back = crypt.decrypt_and_verify(encrypted_data)
Previously Rails 3 was using secret_token
configuration option and encryptor methods were encrypt
decrypt
.