Skip to content

Latest commit

 

History

History
18 lines (11 loc) · 645 Bytes

message_encryptor.md

File metadata and controls

18 lines (11 loc) · 645 Bytes

Message Encryptor

https://api.rubyonrails.org/classes/ActiveSupport/MessageEncryptor.html

It’s pretty similar to MessageVerifier but it keeps the content of the message safe and impossible to read without the key.

It can be used to send sensitive information between services on the client-side (for example in url) or to encrypt data before storing it in the database.

key = SecureRandom.random_bytes(32)
crypt = ActiveSupport::MessageEncryptor.new(key)

message = crypt.encrypt_and_sign('my message')

crypt.decrypt_and_verify(message)
=> "my message"