338
339
340
341
342
343
344
345
346
347
348
349
|
# File 'lib/ruby_smb/dcerpc/samr.rb', line 338
def self.encrypt_password(password, key)
password = RubySMB::Utils.safe_encode(password, 'UTF-16LE').force_encoding('ASCII-8bit')
buffer = password.rjust(512, "\x00") + [ password.length ].pack('V')
salt = SecureRandom.random_bytes(16)
key = OpenSSL::Digest::MD5.new(salt + key).digest
cipher = OpenSSL::Cipher.new('RC4').tap do |cipher|
cipher.encrypt
cipher.key = key
end
cipher.update(buffer) + salt
end
|