class method
self.new
Ruby on Rails 5.2.8.1
Since v2.3.18Signature
self.new(secret, *signature_key_or_options)
Initialize a new MessageEncryptor. secret must be at least as long as the cipher key size. For the default ‘aes-256-gcm’ cipher, this is 256 bits. If you are using a user-entered secret, you can generate a suitable key by using ActiveSupport::KeyGenerator or a similar key derivation function.
First additional parameter is used as the signature key for MessageVerifier. This allows you to specify keys to encrypt and sign data.
ActiveSupport::MessageEncryptor.new('secret', 'signature_secret')
Options:
-
:cipher- Cipher to use. Can be any cipher returned byOpenSSL::Cipher.ciphers. Default is ‘aes-256-gcm’. -
:digest- String of digest to use for signing. Default isSHA1. Ignored when using an AEAD cipher like ‘aes-256-gcm’. -
:serializer- Object serializer to use. Default isMarshal.
Parameters
-
secretreq -
signature_key_or_optionsrest
Source
# File activesupport/lib/active_support/message_encryptor.rb, line 137
def initialize(secret, *signature_key_or_options)
options = signature_key_or_options.extract_options!
sign_secret = signature_key_or_options.first
@secret = secret
@sign_secret = sign_secret
@cipher = options[:cipher] || self.class.default_cipher
@digest = options[:digest] || "SHA1" unless aead_mode?
@verifier = resolve_verifier
@serializer = options[:serializer] || Marshal
end
Defined in activesupport/lib/active_support/message_encryptor.rb line 137
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::MessageEncryptor