update to ruby 1.9. add command line version (passyquick.rb).

This commit is contained in:
swaits committed 2010-09-30 22:37:29 -07:00
1 parent f843df2d7a
commit d2c5ced57a
3 files changed
+126 -7

No files matched your search

+9 -4
View File
@@ -32,6 +32,11 @@ def byte_string(byte, length)
([byte]*length).pack('C*')
end
# helper to make a 'length' long string filled with 'byte'
def byte_array(byte, length)
([byte]*length)
end
# hmac algorithm - returns text version of hmac
def hmac(key, data, digest_object, blocksize)
# if key is too long, hash it
@@ -41,12 +46,12 @@ def hmac(key, data, digest_object, blocksize)
key += byte_string(0,blocksize - key.size) if key.size < blocksize
# create pads
ipad = byte_string(0x36,blocksize)
opad = byte_string(0x5c,blocksize)
blocksize.times { |i| ipad[i] ^= key[i]; opad[i] ^= key[i] }
ipad = byte_array(0x36,blocksize)
opad = byte_array(0x5c,blocksize)
blocksize.times { |i| ipad[i] ^= key[i].ord; opad[i] ^= key[i].ord }
# do the HMAC and return
digest_object.hexdigest( opad + digest_object.digest( ipad + data ) )
digest_object.hexdigest( opad.pack('C*') + digest_object.digest( ipad.pack('C*') + data ) )
end
# hmac-md5