Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
IdentityHelper.cs
Go to the documentation of this file.
1
using
System.IO
;
2
using
System.Reflection
;
3
using
System.Security.Cryptography
;
4
using
System.Text
;
5
6
namespace
System.Security
;
7
8
internal
static
class
IdentityHelper
9
{
10
private
static
readonly
char
[]
s_base32Char
=
new
char
[32]
11
{
12
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
,
'g'
,
'h'
,
'i'
,
'j'
,
13
'k'
,
'l'
,
'm'
,
'n'
,
'o'
,
'p'
,
'q'
,
'r'
,
's'
,
't'
,
14
'u'
,
'v'
,
'w'
,
'x'
,
'y'
,
'z'
,
'0'
,
'1'
,
'2'
,
'3'
,
15
'4'
,
'5'
16
};
17
18
internal
static
string
GetNormalizedUriHash
(
Uri
uri)
19
{
20
return
GetStrongHashSuitableForObjectName
(uri.
ToString
());
21
}
22
23
internal
static
string
GetNormalizedStrongNameHash
(
AssemblyName
name)
24
{
25
byte
[] publicKey = name.GetPublicKey();
26
if
(publicKey ==
null
|| publicKey.Length == 0)
27
{
28
return
null
;
29
}
30
using
MemoryStream
memoryStream =
new
MemoryStream
();
31
using
BinaryWriter
binaryWriter =
new
BinaryWriter
(memoryStream);
32
binaryWriter.Write(publicKey);
33
binaryWriter.Write(name.Version.Major);
34
binaryWriter.Write(name.Name);
35
memoryStream.Position = 0
L
;
36
return
GetStrongHashSuitableForObjectName
(memoryStream);
37
}
38
39
internal
static
string
GetStrongHashSuitableForObjectName
(
string
name)
40
{
41
using
MemoryStream
memoryStream =
new
MemoryStream
();
42
using
BinaryWriter
binaryWriter =
new
BinaryWriter
(memoryStream);
43
binaryWriter.Write(name.ToUpperInvariant());
44
memoryStream.Position = 0
L
;
45
return
GetStrongHashSuitableForObjectName
(memoryStream);
46
}
47
48
internal
static
string
GetStrongHashSuitableForObjectName
(
Stream
stream
)
49
{
50
using
SHA1
sHA =
SHA1
.
Create
();
51
return
ToBase32StringSuitableForDirName
(sHA.ComputeHash(
stream
));
52
}
53
54
internal
static
string
ToBase32StringSuitableForDirName
(
byte
[] buff)
55
{
56
StringBuilder
stringBuilder =
new
StringBuilder
();
57
int
num = buff.Length;
58
int
num2 = 0;
59
do
60
{
61
byte
b = (byte)((num2 < num) ? buff[num2++] : 0);
62
byte
b2 = (byte)((num2 < num) ? buff[num2++] : 0);
63
byte
b3 = (byte)((num2 < num) ? buff[num2++] : 0);
64
byte
b4 = (byte)((num2 < num) ? buff[num2++] : 0);
65
byte
b5 = (byte)((num2 < num) ? buff[num2++] : 0);
66
stringBuilder.
Append
(
s_base32Char
[b & 0x1F]);
67
stringBuilder.
Append
(
s_base32Char
[b2 & 0x1F]);
68
stringBuilder.
Append
(
s_base32Char
[b3 & 0x1F]);
69
stringBuilder.
Append
(
s_base32Char
[b4 & 0x1F]);
70
stringBuilder.
Append
(
s_base32Char
[b5 & 0x1F]);
71
stringBuilder.
Append
(
s_base32Char
[((b & 0xE0) >> 5) | ((b4 & 0x60) >> 2)]);
72
stringBuilder.
Append
(
s_base32Char
[((b2 & 0xE0) >> 5) | ((b5 & 0x60) >> 2)]);
73
b3 >>= 5;
74
if
((b4 & 0x80u) != 0)
75
{
76
b3 = (byte)(b3 | 8u);
77
}
78
if
((b5 & 0x80u) != 0)
79
{
80
b3 = (byte)(b3 | 0x10u);
81
}
82
stringBuilder.
Append
(
s_base32Char
[b3]);
83
}
84
while
(num2 < num);
85
return
stringBuilder.
ToString
();
86
}
87
}
System.IO.BinaryWriter
Definition
BinaryWriter.cs:10
System.IO.MemoryStream
Definition
MemoryStream.cs:9
System.IO.Stream
Definition
Stream.cs:11
System.Reflection.AssemblyName
Definition
AssemblyName.cs:12
System.Security.Cryptography.SHA1.Create
static new SHA1 Create()
Definition
SHA1.cs:55
System.Security.Cryptography.SHA1
Definition
SHA1.cs:7
System.Security.IdentityHelper.GetStrongHashSuitableForObjectName
static string GetStrongHashSuitableForObjectName(Stream stream)
Definition
IdentityHelper.cs:48
System.Security.IdentityHelper.GetStrongHashSuitableForObjectName
static string GetStrongHashSuitableForObjectName(string name)
Definition
IdentityHelper.cs:39
System.Security.IdentityHelper.GetNormalizedUriHash
static string GetNormalizedUriHash(Uri uri)
Definition
IdentityHelper.cs:18
System.Security.IdentityHelper.ToBase32StringSuitableForDirName
static string ToBase32StringSuitableForDirName(byte[] buff)
Definition
IdentityHelper.cs:54
System.Security.IdentityHelper.GetNormalizedStrongNameHash
static string GetNormalizedStrongNameHash(AssemblyName name)
Definition
IdentityHelper.cs:23
System.Security.IdentityHelper.s_base32Char
static readonly char[] s_base32Char
Definition
IdentityHelper.cs:10
System.Security.IdentityHelper
Definition
IdentityHelper.cs:9
System.Text.StringBuilder.ToString
override string ToString()
Definition
StringBuilder.cs:679
System.Text.StringBuilder.Append
StringBuilder Append(char value, int repeatCount)
Definition
StringBuilder.cs:744
System.Text.StringBuilder
Definition
StringBuilder.cs:14
System.Uri.ToString
override string ToString()
Definition
Uri.cs:1119
System.Uri
Definition
Uri.cs:16
System.IO
Definition
ConsoleStream.cs:3
System.Reflection
Definition
ICustomTypeProvider.cs:1
System.Security.Cryptography
Definition
CryptoPool.cs:3
System.Security
Definition
ExtendedProtectionPolicyTypeConverter.cs:8
System.Text
Definition
ConsoleEncoding.cs:1
System.ExceptionArgument.stream
@ stream
System.ConsoleKey.L
@ L
source
System.IO.IsolatedStorage
System.Security
IdentityHelper.cs
Generated by
1.10.0