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
D
E
N
Classes and Modules
Constants
OpenSSLCipherError = OpenSSL::Cipher.const_defined?(:CipherError) ? OpenSSL::Cipher::CipherError : OpenSSL::CipherError
Class Public methods
new(secret, options = {})
    # 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
decrypt(value)
    # 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(value)

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 58
58:     def decrypt_and_verify(value)
59:       _decrypt(verifier.verify(value))
60:     end
encrypt(value)
    # 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(value)

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

    # File activesupport/lib/active_support/message_encryptor.rb, line 52
52:     def encrypt_and_sign(value)
53:       verifier.generate(_encrypt(value))
54:     end