I have this Python script which produces the correct output:
import hashlib
username = "LoginUser"
password = "LoginPass"
nonce = "1234567890"
def LowerCase(s): return s.lower()
def Hex(s): return ''.join([hex(char)[2:] for char in s])
def SHA1(s): h = hashlib.sha1(); h.update(s); return h.digest()
def SHA1Raw(s): h = hashlib.sha1(); h.update(s); return h.hexdigest()
def SHA256(s): h = hashlib.sha256(); h.update(s); return h.digest()
def SHA256Raw(s): h = hashlib.sha256(); h.update(s); return h.hexdigest()
def UTF8Encode(s): return str.encode(s)
step1 = SHA256((UTF8Encode(username)))
step2 = SHA1((UTF8Encode(password)))
step3 = SHA256Raw(step1 + step2)
step1 = SHA256Raw((UTF8Encode(username)))
step2 = SHA1Raw((UTF8Encode(password)))
print("""
SHA256(username={username}) = {step1}
SHA1(password={password}) = {step2}
SHA256((username + password)={username}{password}) = {step3}
""".format(
username = username,
password = password,
step1 = step1,
step2 = step2,
step3 = step3
))
Output:
PS D:\project> python .\test.py
SHA256(username=LoginUser) = 7981673b2c73a6bdb665f347dc89e9d324f542b1fa1c4a700bc523d8a9a6f565
SHA1(password=LoginPass) = df703733447469593d39a125ca93462eade53cab
SHA256((username + password)=LoginUserLoginPass) = cf3066e157468d6a9d59f9ff0662e4f8f8432be4e07c68320a8b6a031d0c022b
Now in Javascript, I try to mirror the functions I have in Python. I cannot for the life of me. I tried quickly understanding Buffers and streams in this context but I believe I am just confusing myself further by not staying grounded to something.
Anyways here's the Javascript versiona and it's output:
const crypto = require('crypto')
const username = "LoginUser"
const password = "LoginPass"
const nonce = "1234567890"
const LowerCase = s => s.toLowerCase()
const Hex = s => Buffer.from(s, 'utf8').toString('hex')
const SHA1 = s => crypto.createHash('sha1').update(s, 'utf8').digest('hex')
const SHA1Raw = s => crypto.createHash('sha1').update(s, 'utf8').digest()
const SHA256 = s => crypto.createHash('sha256').update(s, 'utf8').digest('hex')
const SHA256Raw = s => crypto.createHash('sha256').update(s, 'utf8').digest()
const UTF8Encode = s => Buffer.from(s, 'utf8');
let step1 = SHA256(username)
let step2 = SHA1(password)
let step3 = SHA256Raw(step1.concat(step2))
console.log(`
SHA256(username=${username}) = ${step1}
SHA1(password=${password}) = ${step2}
SHA256((username + password)=${username+password}) = ${step3.toString('hex')}
`)
Output:
PS D:\project> node .\test.js
SHA256(username=LoginUser) = 7981673b2c73a6bdb665f347dc89e9d324f542b1fa1c4a700bc523d8a9a6f565
SHA1(password=LoginPass) = df703733447469593d39a125ca93462eade53cab
SHA256((username + password)=LoginUserLoginPass) = 757101f0fd2628ce12dc039146f56da14a1e85a27fda5d68c2623f616c4fc3cc
Can anyone help?