Hi there,
I'm using the following code to hash a string using sha-1:
Now what I'm trying to do is write a function to return an HMAC (HMAC-SHA-1). I've used the implementations listed on the following links:
And my function so far looks like this:
<%
function hmac(key,text)
dim h 'hash function md5, sha1 etc
dim k 'secret key
dim b 'Blocksize "in bytes" of the hash function (sha1 blocksize = 512 bits : 8bits in byte : 512/8 = 64 bytes)
dim l 'Byte length of the generated hash (sha1 outputs 160 bits : 8bits in byte : 160/8 = 20 bytes)
dim arrSize 'array size for our string byte array. will be "b" above (b-1) as arrays are 0 based
h = "sha1"
k = key '64 bytes to keep it simple
b = 64
l = 20
arrSize = b-1
dim arrIpad()
redim arrIpad(arrSize)
dim arrOpad()
redim arrOpad(arrSize)
dim strIpad
dim strOpad
dim i
'TODO: add code to check key size. made key 64 bytes to keep things simple
for i=0 to arrSize
arrIpad(i) = &h36
arrOpad(i) = &h5c
next
for i=0 to arrSize
arrIpad(i) = arrIpad(i) Xor Asc(CStr(Mid(k,i+1,1)))
arrOpad(i) = arrOpad(i) Xor Asc(CStr(Mid(k,i+1,1)))
strIpad = strIpad & arrIpad(i)
strOpad = strOpad & arrOpad(i)
next
hmac = sha1(strOpad & sha1(strIpad & text))
end function
response.write hmac(")!%rw{LH:[9b|!2A,an_n}]}aLnzTzbHdOIC%Y/?4bC&J[h-+hfM`Lj_>B[/7i#I","hello world")
%>
The expected output is: 1da1b8f5901f02b0d95532acbf9c0db9f7b427ee
Actual output: 85c1891c3a7ba16d0582126ee4849f250fc95c45
I've been at this for ages, can anybody point me in the right direction to get this to work?
Any help would be really appreciated, thanks
I'm using the following code to hash a string using sha-1:
Now what I'm trying to do is write a function to return an HMAC (HMAC-SHA-1). I've used the implementations listed on the following links:
And my function so far looks like this:
<%
function hmac(key,text)
dim h 'hash function md5, sha1 etc
dim k 'secret key
dim b 'Blocksize "in bytes" of the hash function (sha1 blocksize = 512 bits : 8bits in byte : 512/8 = 64 bytes)
dim l 'Byte length of the generated hash (sha1 outputs 160 bits : 8bits in byte : 160/8 = 20 bytes)
dim arrSize 'array size for our string byte array. will be "b" above (b-1) as arrays are 0 based
h = "sha1"
k = key '64 bytes to keep it simple
b = 64
l = 20
arrSize = b-1
dim arrIpad()
redim arrIpad(arrSize)
dim arrOpad()
redim arrOpad(arrSize)
dim strIpad
dim strOpad
dim i
'TODO: add code to check key size. made key 64 bytes to keep things simple
for i=0 to arrSize
arrIpad(i) = &h36
arrOpad(i) = &h5c
next
for i=0 to arrSize
arrIpad(i) = arrIpad(i) Xor Asc(CStr(Mid(k,i+1,1)))
arrOpad(i) = arrOpad(i) Xor Asc(CStr(Mid(k,i+1,1)))
strIpad = strIpad & arrIpad(i)
strOpad = strOpad & arrOpad(i)
next
hmac = sha1(strOpad & sha1(strIpad & text))
end function
response.write hmac(")!%rw{LH:[9b|!2A,an_n}]}aLnzTzbHdOIC%Y/?4bC&J[h-+hfM`Lj_>B[/7i#I","hello world")
%>
The expected output is: 1da1b8f5901f02b0d95532acbf9c0db9f7b427ee
Actual output: 85c1891c3a7ba16d0582126ee4849f250fc95c45
I've been at this for ages, can anybody point me in the right direction to get this to work?
Any help would be really appreciated, thanks