aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails_generator/secret_key_generator.rb
blob: 7dd495a2f5092440ccf748415482be29de243ee5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
require 'active_support/deprecation'

module Rails
  # A class for creating random secret keys. This class will do its best to create a
  # random secret key that's as secure as possible, using whatever methods are
  # available on the current platform. For example:
  #
  #   generator = Rails::SecretKeyGenerator("some unique identifier, such as the application name")
  #   generator.generate_secret     # => "f3f1be90053fa851... (some long string)"
  #
  # This class is *deprecated* in Rails 2.2 in favor of ActiveSupport::SecureRandom.
  # It is currently a wrapper around ActiveSupport::SecureRandom.
  class SecretKeyGenerator
    def initialize(identifier)
    end

    # Generate a random secret key with the best possible method available on
    # the current platform.
    def generate_secret
      ActiveSupport::SecureRandom.hex(64)
    end
    deprecate :generate_secret=>"You should use ActiveSupport::SecureRandom.hex(64)"
  end
end