instance method encrypt

Ruby on Rails 8.0.4

Since v7.0.10

Available in: v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

encrypt(clear_text, key_provider: default_key_provider, cipher_options: {})

Encrypts clean_text and returns the encrypted result.

Internally, it will:

  1. Create a new ActiveRecord::Encryption::Message.

  2. Compress and encrypt clean_text as the message payload.

  3. Serialize it with ActiveRecord::Encryption.message_serializer (ActiveRecord::Encryption::SafeMarshal by default).

  4. Encode the result with Base64.

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.

Parameters

clear_text req
key_provider key = default_key_provider
cipher_options key = {}
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

Type at least 2 characters to search.

↑↓ navigate · open · esc close