323
324
325
326
327
328
329
330
331
332
333
334
|
# File 'lib/ruby_smb/dcerpc/samr.rb', line 323
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
|