1
- using System . Collections . Generic ;
1
+ using MLAPI . NetworkingManagerComponents . Cryptography ;
2
+ using System . Collections . Generic ;
2
3
using System . Security . Cryptography ;
3
4
using System . Text ;
4
5
@@ -15,44 +16,44 @@ public static ulong GetULongHash(string input, bool cache = false)
15
16
if ( cache && ulongCachedHashes . ContainsKey ( input ) )
16
17
return ulongCachedHashes [ input ] ;
17
18
18
- using ( SHA256Managed sha = new SHA256Managed ( ) )
19
- {
20
- byte [ ] hash = sha . ComputeHash ( Encoding . UTF8 . GetBytes ( input ) ) ;
21
- ulong value = hash [ 0 ] | ( ( ulong ) hash [ 1 ] << 8 ) | ( ( ulong ) hash [ 2 ] << 16 ) | ( ( ulong ) hash [ 3 ] << 24 ) | ( ( ulong ) hash [ 4 ] << 32 ) | ( ( ulong ) hash [ 5 ] << 40 ) | ( ( ulong ) hash [ 6 ] << 48 ) | ( ( ulong ) hash [ 7 ] << 56 ) ;
19
+ // using (SHA256Managed sha = new SHA256Managed())
20
+ // {
21
+ // byte[] hash = sha.ComputeHash(Encoding.UTF8.GetBytes(input));
22
+ ulong value = MessageDigest . SHA1_Opt ( Encoding . UTF8 . GetBytes ( input ) ) . CastULong ( ) ; // hash[0] | ((ulong)hash[1] << 8) | ((ulong)hash[2] << 16) | ((ulong)hash[3] << 24) | ((ulong)hash[4] << 32) | ((ulong)hash[5] << 40) | ((ulong)hash[6] << 48) | ((ulong)hash[7] << 56);
22
23
if ( cache )
23
24
ulongCachedHashes . Add ( input , value ) ;
24
25
return value ;
25
- }
26
+ // }
26
27
}
27
28
28
29
public static ulong GetUIntHash ( string input , bool cache = false )
29
30
{
30
31
if ( cache && uintCachedHashes . ContainsKey ( input ) )
31
32
return uintCachedHashes [ input ] ;
32
33
33
- using ( SHA256Managed sha = new SHA256Managed ( ) )
34
- {
35
- byte [ ] hash = sha . ComputeHash ( Encoding . UTF8 . GetBytes ( input ) ) ;
36
- uint value = hash [ 0 ] | ( ( uint ) hash [ 1 ] << 8 ) | ( ( uint ) hash [ 2 ] << 16 ) | ( ( uint ) hash [ 3 ] << 24 ) ;
34
+ // using (SHA256Managed sha = new SHA256Managed())
35
+ // {
36
+ // byte[] hash = sha.ComputeHash(Encoding.UTF8.GetBytes(input));
37
+ uint value = MessageDigest . SHA1_Opt ( Encoding . UTF8 . GetBytes ( input ) ) . CastUInt ( ) ; // hash[0] | ((uint)hash[1] << 8) | ((uint)hash[2] << 16) | ((uint)hash[3] << 24);
37
38
if ( cache )
38
39
uintCachedHashes . Add ( input , value ) ;
39
40
return value ;
40
- }
41
+ // }
41
42
}
42
43
43
44
public static ushort GetUShortHash ( string input , bool cache = false )
44
45
{
45
46
if ( cache && ushortCachedHashes . ContainsKey ( input ) )
46
47
return ushortCachedHashes [ input ] ;
47
48
48
- using ( SHA256Managed sha = new SHA256Managed ( ) )
49
- {
50
- byte [ ] hash = sha . ComputeHash ( Encoding . UTF8 . GetBytes ( input ) ) ;
51
- ushort value = ( ushort ) ( hash [ 0 ] | ( ushort ) ( hash [ 1 ] << 8 ) ) ;
49
+ // using (SHA256Managed sha = new SHA256Managed())
50
+ // {
51
+ // byte[] hash = sha.ComputeHash(Encoding.UTF8.GetBytes(input));
52
+ ushort value = MessageDigest . SHA1_Opt ( Encoding . UTF8 . GetBytes ( input ) ) . CastUShort ( ) ; // (ushort)(hash[0] | (ushort)(hash[1] << 8));
52
53
if ( cache )
53
54
ushortCachedHashes . Add ( input , value ) ;
54
55
return value ;
55
- }
56
+ // }
56
57
}
57
58
}
58
59
}
0 commit comments