Moving nextgen from a branch to the trunk!!!

git-svn-id: https://beef.googlecode.com/svn/trunk@908 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9
This commit is contained in:
scotty.b.brown@gmail.com
2011-04-20 07:54:56 +00:00
parent af413eecdb
commit 35f62714b1
502 changed files with 69628 additions and 0 deletions

30
core/main/crypto.rb Normal file
View File

@@ -0,0 +1,30 @@
module BeEF
module Core
#
# This module provides crypto functionality
#
module Crypto
# the minimum length of the security token
TOKEN_MINIMUM_LENGTH = 15
#
# Generate a secure random token
#
# @param: {Integer} the length of the secure token
#
def self.secure_token(len = nil)
# get default length from config
config = BeEF::Core::Configuration.instance
token_length = len || config.get('beef.crypto_default_value_length').to_i
# type checking
raise Exception::TypeError, "Token length is less than the minimum length enforced by the framework: #{TOKEN_MINIMUM_LENGTH}" if (token_length < TOKEN_MINIMUM_LENGTH)
# return random hex string
return OpenSSL::Random.random_bytes(token_length).unpack("H*")[0]
end
end
end
end