class

ActiveSupport::MessageEncryptor

Inherits Reference < Object

Constants

AUTH_TAG_LENGTH = 16
SEPARATOR = "--"

Constructors

new(secret : String | Bytes, cipher : String = "aes-256-gcm", url_safe : Bool = false, serializer : Symbol = :json, force_legacy_metadata_serializer : Bool = false)
Source

Class methods

iv_len(cipher : String = "aes-256-gcm") : Int32
Source
key_len(cipher : String = "aes-256-gcm") : Int32

iv aes-256-gcm = 12 байт, ключ = 32 байта.

Source

Instance methods

decrypt_and_verify(message : String, purpose : String | Nil = nil) : JSON::Any | String | Nil

Расшифровывает и проверяет тег. Ошибки формата (base64, разделители, длина тега, провал аутентификации) — InvalidMessage, как в геме; несоответствие purpose/истёкший срок — nil.

Source
encrypt_and_sign(value : MetadataPayload, purpose : String | Nil = nil, expires_in : Time::Span | Nil = nil, expires_at : Time | Nil = nil) : String

Шифрует значение. С purpose/exp — конверт {"_rails":{...}} (data-конверт Rails 8.1). NullSerializer: значение — строка как есть.

Source

Nested types