mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-21 17:37:50 -05:00
Brought up to date with the private repository (feea4c7)
This commit is contained in:
1 parent
1aa738d692
commit
1b1df1ae48
7925 files changed
+2617237
-20
No files matched your search
@@ -0,0 +1,76 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class HMAC
|
||||
{
|
||||
|
||||
private var hash:IHash;
|
||||
|
||||
private var bits:uint;
|
||||
|
||||
public function HMAC(hash:IHash, bits:uint = 0)
|
||||
{
|
||||
super();
|
||||
this.hash = hash;
|
||||
this.bits = bits;
|
||||
}
|
||||
|
||||
public function getHashSize() : uint
|
||||
{
|
||||
if(this.bits != 0)
|
||||
{
|
||||
return this.bits / 8;
|
||||
}
|
||||
return this.hash.getHashSize();
|
||||
}
|
||||
|
||||
public function compute(key:ByteArray, data:ByteArray) : ByteArray
|
||||
{
|
||||
var hashKey:ByteArray = null;
|
||||
if(key.length > this.hash.getInputSize())
|
||||
{
|
||||
hashKey = this.hash.hash(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
hashKey = new ByteArray();
|
||||
hashKey.writeBytes(key);
|
||||
}
|
||||
while(hashKey.length < this.hash.getInputSize())
|
||||
{
|
||||
hashKey[hashKey.length] = 0;
|
||||
}
|
||||
var innerKey:ByteArray = new ByteArray();
|
||||
var outerKey:ByteArray = new ByteArray();
|
||||
for(var i:uint = 0; i < hashKey.length; i++)
|
||||
{
|
||||
innerKey[i] = hashKey[i] ^ 0x36;
|
||||
outerKey[i] = hashKey[i] ^ 0x5C;
|
||||
}
|
||||
innerKey.position = hashKey.length;
|
||||
innerKey.writeBytes(data);
|
||||
var innerHash:ByteArray = this.hash.hash(innerKey);
|
||||
outerKey.position = hashKey.length;
|
||||
outerKey.writeBytes(innerHash);
|
||||
var outerHash:ByteArray = this.hash.hash(outerKey);
|
||||
if(this.bits > 0 && this.bits < 8 * outerHash.length)
|
||||
{
|
||||
outerHash.length = this.bits / 8;
|
||||
}
|
||||
return outerHash;
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
this.hash = null;
|
||||
this.bits = 0;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "hmac-" + (this.bits > 0 ? this.bits + "-" : "") + this.hash.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user