Core: Updated to 11.0.7
Port From (https://github.com/TrinityCore/TrinityCore/commit/4f7079f471401d5cf7885351baabc027813f60f5)
This commit is contained in:
@@ -5,16 +5,16 @@ using System.Security.Cryptography;
|
||||
|
||||
namespace Framework.Cryptography
|
||||
{
|
||||
public class SessionKeyGenerator256
|
||||
public class SessionKeyGenerator512
|
||||
{
|
||||
public SessionKeyGenerator256(byte[] buff, int size = 0)
|
||||
public SessionKeyGenerator512(byte[] buff, int size = 0)
|
||||
{
|
||||
if (size == 0)
|
||||
size = buff.Length;
|
||||
|
||||
int halfSize = size / 2;
|
||||
|
||||
sh = SHA256.Create();
|
||||
sh = SHA512.Create();
|
||||
sh.TransformFinalBlock(buff, 0, halfSize);
|
||||
o1 = sh.Hash;
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Framework.Cryptography
|
||||
taken = 0;
|
||||
}
|
||||
|
||||
SHA256 sh;
|
||||
SHA512 sh;
|
||||
uint taken;
|
||||
byte[] o0 = new byte[32];
|
||||
byte[] o1 = new byte[32];
|
||||
|
||||
@@ -52,6 +52,51 @@ namespace Framework.Cryptography
|
||||
public byte[] Digest { get; private set; }
|
||||
}
|
||||
|
||||
public class Sha512
|
||||
{
|
||||
public Sha512()
|
||||
{
|
||||
sha = SHA512.Create();
|
||||
sha.Initialize();
|
||||
}
|
||||
|
||||
public void Process(byte[] data, int length)
|
||||
{
|
||||
sha.TransformBlock(data, 0, length, data, 0);
|
||||
}
|
||||
|
||||
public void Process(uint data)
|
||||
{
|
||||
var bytes = BitConverter.GetBytes(data);
|
||||
|
||||
sha.TransformBlock(bytes, 0, 4, bytes, 0);
|
||||
}
|
||||
|
||||
public void Process(string data)
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes(data);
|
||||
|
||||
sha.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
|
||||
}
|
||||
|
||||
public void Finish(byte[] data)
|
||||
{
|
||||
sha.TransformFinalBlock(data, 0, data.Length);
|
||||
|
||||
Digest = sha.Hash;
|
||||
}
|
||||
|
||||
public void Finish(byte[] data, int offset, int length)
|
||||
{
|
||||
sha.TransformFinalBlock(data, offset, length);
|
||||
|
||||
Digest = sha.Hash;
|
||||
}
|
||||
|
||||
SHA512 sha;
|
||||
public byte[] Digest { get; private set; }
|
||||
}
|
||||
|
||||
public class HmacHash : HMACSHA1
|
||||
{
|
||||
public HmacHash(byte[] key) : base(key)
|
||||
@@ -132,4 +177,40 @@ namespace Framework.Cryptography
|
||||
|
||||
public byte[] Digest { get; private set; }
|
||||
}
|
||||
|
||||
public class HmacSha512 : HMACSHA512
|
||||
{
|
||||
public HmacSha512(byte[] key) : base(key)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public void Process(byte[] data, int length)
|
||||
{
|
||||
TransformBlock(data, 0, length, data, 0);
|
||||
}
|
||||
|
||||
public void Process(uint data)
|
||||
{
|
||||
var bytes = BitConverter.GetBytes(data);
|
||||
|
||||
TransformBlock(bytes, 0, bytes.Length, bytes, 0);
|
||||
}
|
||||
|
||||
public void Process(string data)
|
||||
{
|
||||
var bytes = Encoding.ASCII.GetBytes(data);
|
||||
|
||||
TransformBlock(bytes, 0, bytes.Length, bytes, 0);
|
||||
}
|
||||
|
||||
public void Finish(byte[] data, int length)
|
||||
{
|
||||
TransformFinalBlock(data, 0, length);
|
||||
|
||||
Digest = Hash;
|
||||
}
|
||||
|
||||
public byte[] Digest { get; private set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user