instance method
encrypt
Ruby on Rails 8.1.2
Since v7.0.10Signature
encrypt(clear_text, key_provider: default_key_provider, cipher_options: {})
Encrypts clean_text and returns the encrypted result.
Internally, it will:
-
Create a new ActiveRecord::Encryption::Message.
-
Compress and encrypt
clean_textas the message payload. -
Serialize it with
ActiveRecord::Encryption.message_serializer(ActiveRecord::Encryption::SafeMarshalby default). -
Encode the result with Base64.
Options
:key_provider-
Key provider to use for the encryption operation. It will default to
ActiveRecord::Encryption.key_providerwhen not provided. :cipher_options-
Cipher-specific options that will be passed to the Cipher configured in
ActiveRecord::Encryption.cipher.
Parameters
-
clear_textreq -
key_providerkey = default_key_provider -
cipher_optionskey = {}
Source
# File activerecord/lib/active_record/encryption/encryptor.rb, line 51
def encrypt(clear_text, key_provider: default_key_provider, cipher_options: {})
clear_text = force_encoding_if_needed(clear_text) if cipher_options[:deterministic]
validate_payload_type(clear_text)
serialize_message build_encrypted_message(clear_text, key_provider: key_provider, cipher_options: cipher_options)
end
Defined in activerecord/lib/active_record/encryption/encryptor.rb line 51
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Encryption::Encryptor