Skip to content

Instantly share code, notes, and snippets.

@jigneshkhokhani
Created February 23, 2018 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jigneshkhokhani/e1c45115dd9d48be2f0f60210243ef5b to your computer and use it in GitHub Desktop.
Save jigneshkhokhani/e1c45115dd9d48be2f0f60210243ef5b to your computer and use it in GitHub Desktop.
[Encrypt/Decrypt] Load after decrypt and dump after encrypt in DB
# lib/encrypted_coder.rb
class EncryptedCoder
include Crypt
def load(value)
return unless value.present?
Marshal.load(
Crypt.decrypt(
Base64.decode64(value)))
end
def dump(value)
Base64.encode64(
Crypt.encrypt(
Marshal.dump(value)))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment