Module: Smbhash

Defined in:
lib/smbhash.rb,
lib/smbhash/methods18.rb,
lib/smbhash/methods19.rb

Defined Under Namespace

Modules: Methods18, Methods19, Private

Class Method Summary collapse

Class Method Details

.lm_hash(password, encoding = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/smbhash.rb', line 5

def lm_hash(password, encoding=nil)
  dos_password = Private.convert_encoding("ISO-8859-1",
                                          encoding || "UTF-8",
                                          password.upcase)
  fail ArgumentError, 'Password must be < 14 characters in ISO-8859-1' if dos_password.size > 14

  Private.encrypt_14characters(dos_password).unpack("C*").collect do |char|
    "%02X" % char
  end.join
end

.ntlm_hash(password, encoding = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/smbhash.rb', line 16

def ntlm_hash(password, encoding=nil)
  ucs2_password = Private.convert_encoding("UTF-16LE",
                                           encoding || "UTF-8",
                                           password)

  fail ArgumentError, 'Password must be < 255 characters in UTF-16LE' if ucs2_password.size > 255

  hex = OpenSSL::Digest::MD4.new(ucs2_password).hexdigest.upcase
  hex
end

.ntlmgen(password, encoding = nil) ⇒ Object



27
28
29
30
31
32
# File 'lib/smbhash.rb', line 27

def ntlmgen(password, encoding=nil)    
  [
    lm_hash(password, encoding),
    ntlm_hash(password, encoding)
  ]
end