Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SymmetricImportExportExtensions.cs
Go to the documentation of this file.
1
using
System
;
2
using
System.IO
;
3
using
System.Security.Cryptography
;
4
using
System.Text
;
5
6
namespace
Internal.Cryptography
;
7
8
internal
static
class
SymmetricImportExportExtensions
9
{
10
private
static
readonly
CngKeyBlobFormat
s_cipherKeyBlobFormat
=
new
CngKeyBlobFormat
(
"CipherKeyBlob"
);
11
12
public
static
byte
[]
GetSymmetricKeyDataIfExportable
(
this
CngKey
cngKey,
string
algorithm)
13
{
14
byte
[]
buffer
= cngKey.
Export
(
s_cipherKeyBlobFormat
);
15
using
MemoryStream
input
=
new
MemoryStream
(
buffer
);
16
using
BinaryReader
binaryReader =
new
BinaryReader
(
input
,
Encoding
.
Unicode
);
17
int
num = binaryReader.ReadInt32();
18
if
(num != 16)
19
{
20
throw
new
CryptographicException
(
System
.
SR
.
Cryptography_KeyBlobParsingError
);
21
}
22
int
num2 = binaryReader.ReadInt32();
23
if
(num2 != 1380470851)
24
{
25
throw
new
CryptographicException
(
System
.
SR
.
Cryptography_KeyBlobParsingError
);
26
}
27
int
num3 = binaryReader.ReadInt32();
28
binaryReader.ReadInt32();
29
string
text
=
new
string
(binaryReader.ReadChars(num3 / 2 - 1));
30
if
(
text
!= algorithm)
31
{
32
throw
new
CryptographicException
(
System
.
SR
.
Format
(
System
.
SR
.
Cryptography_CngKeyWrongAlgorithm
,
text
, algorithm));
33
}
34
if
(binaryReader.ReadChar() != 0)
35
{
36
throw
new
CryptographicException
(
System
.
SR
.
Cryptography_KeyBlobParsingError
);
37
}
38
int
num4 = binaryReader.ReadInt32();
39
if
(num4 != 1296188491)
40
{
41
throw
new
CryptographicException
(
System
.
SR
.
Cryptography_KeyBlobParsingError
);
42
}
43
int
num5 = binaryReader.ReadInt32();
44
if
(num5 != 1)
45
{
46
throw
new
CryptographicException
(
System
.
SR
.
Cryptography_KeyBlobParsingError
);
47
}
48
int
count
= binaryReader.ReadInt32();
49
return
binaryReader.ReadBytes(
count
);
50
}
51
}
Internal.Cryptography.SymmetricImportExportExtensions.GetSymmetricKeyDataIfExportable
static byte[] GetSymmetricKeyDataIfExportable(this CngKey cngKey, string algorithm)
Definition
SymmetricImportExportExtensions.cs:12
Internal.Cryptography.SymmetricImportExportExtensions.s_cipherKeyBlobFormat
static readonly CngKeyBlobFormat s_cipherKeyBlobFormat
Definition
SymmetricImportExportExtensions.cs:10
Internal.Cryptography.SymmetricImportExportExtensions
Definition
SymmetricImportExportExtensions.cs:9
System.IO.BinaryReader
Definition
BinaryReader.cs:8
System.IO.MemoryStream
Definition
MemoryStream.cs:9
System.SR.Format
static string Format(string resourceFormat, object p1)
Definition
SR.cs:118
System.SR.Cryptography_CngKeyWrongAlgorithm
static string Cryptography_CngKeyWrongAlgorithm
Definition
SR.cs:42
System.SR.Cryptography_KeyBlobParsingError
static string Cryptography_KeyBlobParsingError
Definition
SR.cs:86
System.SR
Definition
SR.cs:7
System.Security.Cryptography.CngKeyBlobFormat
Definition
CngKeyBlobFormat.cs:6
System.Security.Cryptography.CngKey.Export
byte[] Export(CngKeyBlobFormat format)
Definition
CngKey.cs:622
System.Security.Cryptography.CngKey
Definition
CngKey.cs:10
System.Security.Cryptography.CryptographicException
Definition
CryptographicException.cs:9
System.Text.Encoding.Unicode
static Encoding Unicode
Definition
Encoding.cs:519
System.Text.Encoding
Definition
Encoding.cs:15
string
Internal.Cryptography
Definition
AesBCryptModes.cs:5
System.IO
Definition
ConsoleStream.cs:3
System.Security.Cryptography
Definition
CryptoPool.cs:3
System.Text
Definition
ConsoleEncoding.cs:1
System.ExceptionArgument.text
@ text
System.ExceptionArgument.buffer
@ buffer
System.ExceptionArgument.input
@ input
System.ExceptionArgument.count
@ count
System
Definition
BlockingCollection.cs:8
source
System.Security.Cryptography.Cng
Internal.Cryptography
SymmetricImportExportExtensions.cs
Generated by
1.10.0