instance method
generate_random_hex_key
Ruby on Rails 7.0.10
Since v7.0.10Signature
generate_random_hex_key(length: key_length)
Returns a random key in hexadecimal format. The key will have a size in bytes of :length (configured Cipher‘s length by default)
Hexadecimal format is handy for representing keys as printable text. To maximize the space of characters used, it is good practice including not printable characters. Hexadecimal format ensures that generated keys are representable with plain text
To convert back to the original string with the desired length:
[ value ].pack("H*")
Parameters
-
lengthkey = key_length
Source
# File activerecord/lib/active_record/encryption/key_generator.rb, line 24
def generate_random_hex_key(length: key_length)
generate_random_key(length: length).unpack("H*")[0]
end
Defined in activerecord/lib/active_record/encryption/key_generator.rb line 24
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Encryption::KeyGenerator