Method: ActiveRecord::Encryption::Encryptor#encrypt
- Defined in:
- lib/active_record/encryption/encryptor.rb
#encrypt(clear_text, key_provider: default_key_provider, cipher_options: {}) ⇒ Object
Encrypts clean_text
and returns the encrypted result
Internally, it will:
-
Create a new ActiveRecord::Encryption::Message
-
Compress and encrypt
clean_text
as the message payload -
Serialize it with
ActiveRecord::Encryption.message_serializer
(ActiveRecord::Encryption::SafeMarshal
by default) -
Encode the result with Base 64
Options
- :key_provider
-
Key provider to use for the encryption operation. It will default to
ActiveRecord::Encryption.key_provider
when not provided. - :cipher_options
-
Cipher-specific options that will be passed to the Cipher configured in
ActiveRecord::Encryption.cipher
49 50 51 52 53 54 |
# File 'lib/active_record/encryption/encryptor.rb', line 49 def encrypt(clear_text, key_provider: default_key_provider, cipher_options: {}) clear_text = force_encoding_if_needed(clear_text) if [:deterministic] validate_payload_type(clear_text) (clear_text, key_provider: key_provider, cipher_options: ) end |