diff options
author | Stephen Touset <stephen@touset.org> | 2013-03-28 10:17:31 -0700 |
---|---|---|
committer | Stephen Touset <stephen@touset.org> | 2013-03-28 10:17:31 -0700 |
commit | 9ec0cf8581ef83bb1512293750aa0a7b32e2f4dd (patch) | |
tree | 9e31d6640e774c160c5f9f0f34ea61a7c0e4eb18 /activesupport | |
parent | b77b95eaa27a38ade8ddeb7c5b9a816cc41a1590 (diff) | |
download | rails-9ec0cf8581ef83bb1512293750aa0a7b32e2f4dd.tar.gz rails-9ec0cf8581ef83bb1512293750aa0a7b32e2f4dd.tar.bz2 rails-9ec0cf8581ef83bb1512293750aa0a7b32e2f4dd.zip |
Improve poor security recommendation in docs
As reported in #9960, the current documentation recommends an insecure practice for
key generation from a password (a single round of SHA-256). The modified documentation
uses ActiveSupport::KeyGenerator to perform proper key stretching.
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/message_encryptor.rb | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/message_encryptor.rb b/activesupport/lib/active_support/message_encryptor.rb index ce40a7d689..0109a108be 100644 --- a/activesupport/lib/active_support/message_encryptor.rb +++ b/activesupport/lib/active_support/message_encryptor.rb @@ -12,10 +12,11 @@ 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. # - # key = OpenSSL::Digest::SHA256.new('password').digest # => "\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" + # salt = SecureRandom.random_bytes(64) + # key = ActiveSupport::KeyGenerator.new('password').generate_key(salt) # => "\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 module NullSerializer #:nodoc: def self.load(value) |