git-svn-id: https://beef.googlecode.com/svn/trunk@503 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9
27 lines
526 B
Ruby
27 lines
526 B
Ruby
module BeEF
|
|
|
|
#
|
|
# This module provides crypto functionality
|
|
#
|
|
module Crypto
|
|
|
|
#
|
|
# Generate a secure random token
|
|
#
|
|
def self.secure_token(len = nil)
|
|
|
|
# get default length from config
|
|
config = BeEF::Configuration.instance
|
|
token_length = len || config.get('crypto_default_value_length').to_i
|
|
|
|
raise WEBrick::HTTPStatus::BadRequest, "Token length is zero or less" if (1 > token_length)
|
|
|
|
# return random hex string
|
|
OpenSSL::Random.random_bytes(token_length).unpack("H*")[0]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|