Class: Faker::Crypto

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/default/crypto.rb

Constant Summary collapse

MD5_MIN_NUMBER_OF_CHARACTERS =

Setting the lorem character number lower than the default of 255 reduces the time complexity of each hash algorithm while still returning deterministically unique values. See github.com/faker-ruby/faker/pull/2938 for more info.

25
SHA1_MIN_NUMBER_OF_CHARACTERS =
31
SHA256_MIN_NUMBER_OF_CHARACTERS =
50
SHA512_MIN_NUMBER_OF_CHARACTERS =
100

Constants inherited from Base

Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters

Class Method Summary collapse

Methods inherited from Base

bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, generate, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, shuffle!, translate, unique, with_locale

Class Method Details

.md5String

Produces an MD5 hash.

Examples:

Faker::Crypto.md5 #=> "6b5ed240042e8a65c55ddb826c3408e6"

Returns:

  • (String)

Available since:

  • 1.6.4



26
27
28
# File 'lib/faker/default/crypto.rb', line 26

def md5
  OpenSSL::Digest::MD5.hexdigest(Lorem.characters(number: MD5_MIN_NUMBER_OF_CHARACTERS))
end

.sha1String

Produces a SHA1 hash.

Examples:

Faker::Crypto.sha1 #=> "4e99e31c51eef8b2d290e709f757f92e558a503f"

Returns:

  • (String)

Available since:

  • 1.6.4



39
40
41
# File 'lib/faker/default/crypto.rb', line 39

def sha1
  OpenSSL::Digest::SHA1.hexdigest(Lorem.characters(number: SHA1_MIN_NUMBER_OF_CHARACTERS))
end

.sha256String

Produces a SHA256 hash.

Examples:

Faker::Crypto.sha256 #=> "51e4dbb424cd9db1ec5fb989514f2a35652ececef33f21c8dd1fd61bb8e3929d"

Returns:

  • (String)

Available since:

  • 1.6.4



52
53
54
# File 'lib/faker/default/crypto.rb', line 52

def sha256
  OpenSSL::Digest::SHA256.hexdigest(Lorem.characters(number: SHA256_MIN_NUMBER_OF_CHARACTERS))
end

.sha512String

Produces a SHA512 hash.

Examples:

Faker::Crypto.sha512 #=> "7b9fc82a6642874833d01b74a7b4fae3d15373193b55cfba47327f8f0afdc8d0ea155b58639a03a887009ef997dab8dd8d36767620d430f6e787e5996e26da80"

Returns:

  • (String)

Available since:

  • next



65
66
67
# File 'lib/faker/default/crypto.rb', line 65

def sha512
  OpenSSL::Digest::SHA512.hexdigest(Lorem.characters(number: SHA512_MIN_NUMBER_OF_CHARACTERS))
end