MessageEncryptor is a simple way to encrypt values which get stored somewhere you don’t trust.
The cipher text and initialization vector are base64 encoded and returned to you.
This can be used in situations similar to the MessageVerifier, but where you don’t want users to be able to determine the value of the payload.
Methods
Classes and Modules
- MODULE ActiveSupport::MessageEncryptor::NullSerializer
- CLASS ActiveSupport::MessageEncryptor::InvalidMessage
Constants
OpenSSLCipherError | = | OpenSSL::Cipher.const_defined?(:CipherError) ? OpenSSL::Cipher::CipherError : OpenSSL::CipherError |
Class Public methods
# File activesupport/lib/active_support/message_encryptor.rb, line 26 26: def initialize(secret, options = {}) 27: unless options.is_a?(Hash) 28: ActiveSupport::Deprecation.warn "The second parameter should be an options hash. Use :cipher => 'algorithm' to specify the cipher algorithm." 29: options = { :cipher => options } 30: end 31: 32: @secret = secret 33: @cipher = options[:cipher] || 'aes-256-cbc' 34: @verifier = MessageVerifier.new(@secret, :serializer => NullSerializer) 35: @serializer = options[:serializer] || Marshal 36: end
Instance Public methods
# File activesupport/lib/active_support/message_encryptor.rb, line 44 44: def decrypt(value) 45: ActiveSupport::Deprecation.warn "MessageEncryptor#decrypt is deprecated as it is not safe without a signature. " \ 46: "Please use MessageEncryptor#decrypt_and_verify instead." 47: _decrypt(value) 48: end
Decrypt and verify a message. We need to verify the message in order to avoid padding attacks. Reference: www.limited-entropy.com/padding-oracle-attacks
# File activesupport/lib/active_support/message_encryptor.rb, line 38 38: def encrypt(value) 39: ActiveSupport::Deprecation.warn "MessageEncryptor#encrypt is deprecated as it is not safe without a signature. " \ 40: "Please use MessageEncryptor#encrypt_and_sign instead." 41: _encrypt(value) 42: end
Encrypt and sign a message. We need to sign the message in order to avoid padding attacks. Reference: www.limited-entropy.com/padding-oracle-attacks