5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/neotelis_pay/utils/crypt.rb', line 5
def self.crypt_md5(source_msg, key)
k_ipad = Array.new(64, 54)
k_opad = Array.new(64, 92)
key_arr = key.unpack('c*')
for i in 0..(key_arr.size - 1)
k_ipad[i] = key_arr[i] ^ 54
k_opad[i] = key_arr[i] ^ 92
end
k_ipad_str = k_ipad.pack('c*')
k_opad_str = k_opad.pack('c*')
md1 = ''
md2 = ''
md1 = Digest::MD5.digest(k_ipad_str + source_msg)
md2 = Digest::MD5.hexdigest(k_opad_str + md1)
return md1, md2
end
|