diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2017-07-09 18:24:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-09 18:24:12 +0200 |
commit | 85d154f05214c113c4afd218f5d51df7d9dae144 (patch) | |
tree | f312f1ad7e963f6496f221e9fa95603d3c4c75a4 /activesupport/lib/active_support | |
parent | b362ce6d544a1dcaef08eaf2c685f8495f94c51c (diff) | |
parent | 062283d9d321eae0008d71892e6e56e041f88827 (diff) | |
download | rails-85d154f05214c113c4afd218f5d51df7d9dae144.tar.gz rails-85d154f05214c113c4afd218f5d51df7d9dae144.tar.bz2 rails-85d154f05214c113c4afd218f5d51df7d9dae144.zip |
Merge pull request #29730 from bdewater/update-encryptor-docs
Update MessageEncryptor example to use dynamic key length
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/message_encryptor.rb | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/message_encryptor.rb b/activesupport/lib/active_support/message_encryptor.rb index 689a2202f7..03e7d5b436 100644 --- a/activesupport/lib/active_support/message_encryptor.rb +++ b/activesupport/lib/active_support/message_encryptor.rb @@ -14,11 +14,12 @@ module ActiveSupport # This can be used in situations similar to the <tt>MessageVerifier</tt>, but # where you don't want users to be able to determine the value of the payload. # - # salt = SecureRandom.random_bytes(64) - # key = ActiveSupport::KeyGenerator.new('password').generate_key(salt, 32) # => "\x89\xE0\x156\xAC..." - # crypt = ActiveSupport::MessageEncryptor.new(key) # => #<ActiveSupport::MessageEncryptor ...> - # encrypted_data = crypt.encrypt_and_sign('my secret data') # => "NlFBTTMwOUV5UlA1QlNEN2xkY2d6eThYWWh..." - # crypt.decrypt_and_verify(encrypted_data) # => "my secret data" + # len = ActiveSupport::MessageEncryptor.key_len + # salt = SecureRandom.random_bytes(len) + # key = ActiveSupport::KeyGenerator.new('password').generate_key(salt, len) # => "\x89\xE0\x156\xAC..." + # crypt = ActiveSupport::MessageEncryptor.new(key) # => #<ActiveSupport::MessageEncryptor ...> + # encrypted_data = crypt.encrypt_and_sign('my secret data') # => "NlFBTTMwOUV5UlA1QlNEN2xkY2d6eThYWWh..." + # crypt.decrypt_and_verify(encrypted_data) # => "my secret data" class MessageEncryptor class << self attr_accessor :use_authenticated_message_encryption #:nodoc: |