Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
RSAPssX509SignatureGenerator.cs
Go to the documentation of this file.
3
5
7{
8 private readonly RSA _key;
9
10 private readonly RSASignaturePadding _padding;
11
13 {
14 _key = key;
15 _padding = padding;
16 }
17
18 public override byte[] GetSignatureAlgorithmIdentifier(HashAlgorithmName hashAlgorithm)
19 {
21 {
23 }
24 int saltLength;
25 string text;
26 if (hashAlgorithm == HashAlgorithmName.SHA256)
27 {
28 saltLength = 32;
29 text = "2.16.840.1.101.3.4.2.1";
30 }
31 else if (hashAlgorithm == HashAlgorithmName.SHA384)
32 {
33 saltLength = 48;
34 text = "2.16.840.1.101.3.4.2.2";
35 }
36 else
37 {
38 if (!(hashAlgorithm == HashAlgorithmName.SHA512))
39 {
40 throw new ArgumentOutOfRangeException("hashAlgorithm", hashAlgorithm, System.SR.Format(System.SR.Cryptography_UnknownHashAlgorithm, hashAlgorithm.Name));
41 }
42 saltLength = 64;
43 text = "2.16.840.1.101.3.4.2.3";
44 }
45 PssParamsAsn pssParamsAsn = default(PssParamsAsn);
47 {
48 Algorithm = text
49 };
50 pssParamsAsn.MaskGenAlgorithm = new System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn
51 {
52 Algorithm = "1.2.840.113549.1.1.8"
53 };
54 pssParamsAsn.SaltLength = saltLength;
55 pssParamsAsn.TrailerField = 1;
56 PssParamsAsn pssParamsAsn2 = pssParamsAsn;
57 AsnWriter asnWriter = new AsnWriter(AsnEncodingRules.DER);
58 using (asnWriter.PushSequence())
59 {
60 asnWriter.WriteObjectIdentifierForCrypto(text);
61 }
62 pssParamsAsn2.MaskGenAlgorithm.Parameters = asnWriter.Encode();
63 asnWriter.Reset();
64 pssParamsAsn2.Encode(asnWriter);
66 algorithmIdentifierAsn.Algorithm = "1.2.840.113549.1.1.10";
67 algorithmIdentifierAsn.Parameters = asnWriter.Encode();
68 System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn algorithmIdentifierAsn2 = algorithmIdentifierAsn;
69 asnWriter.Reset();
70 algorithmIdentifierAsn2.Encode(asnWriter);
71 return asnWriter.Encode();
72 }
73
74 public override byte[] SignData(byte[] data, HashAlgorithmName hashAlgorithm)
75 {
76 return _key.SignData(data, hashAlgorithm, _padding);
77 }
78
83}
Scope PushSequence(Asn1Tag? tag=null)
int Encode(Span< byte > destination)
Definition AsnWriter.cs:195
static string Cryptography_UnknownHashAlgorithm
Definition SR.cs:152
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Cryptography_InvalidPaddingMode
Definition SR.cs:46
Definition SR.cs:7
byte[] SignData(byte[] data, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Definition RSA.cs:173
override byte[] SignData(byte[] data, HashAlgorithmName hashAlgorithm)