Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
RSAPkcs1X509SignatureGenerator.cs
Go to the documentation of this file.
2
4
6{
7 private readonly RSA _key;
8
10 {
11 _key = key;
12 }
13
14 public override byte[] SignData(byte[] data, HashAlgorithmName hashAlgorithm)
15 {
16 return _key.SignData(data, hashAlgorithm, RSASignaturePadding.Pkcs1);
17 }
18
19 protected override PublicKey BuildPublicKey()
20 {
21 return BuildPublicKey(_key);
22 }
23
24 internal static PublicKey BuildPublicKey(RSA rsa)
25 {
27 Oid oid = rsaOid;
28 Oid oid2 = rsaOid;
29 Span<byte> span = stackalloc byte[2] { 5, 0 };
30 return new PublicKey(oid, new AsnEncodedData(oid2, span), new AsnEncodedData(rsaOid, rsa.ExportRSAPublicKey()));
31 }
32
33 public override byte[] GetSignatureAlgorithmIdentifier(HashAlgorithmName hashAlgorithm)
34 {
35 string oidValue;
36 if (hashAlgorithm == HashAlgorithmName.SHA256)
37 {
38 oidValue = "1.2.840.113549.1.1.11";
39 }
40 else if (hashAlgorithm == HashAlgorithmName.SHA384)
41 {
42 oidValue = "1.2.840.113549.1.1.12";
43 }
44 else
45 {
46 if (!(hashAlgorithm == HashAlgorithmName.SHA512))
47 {
48 throw new ArgumentOutOfRangeException("hashAlgorithm", hashAlgorithm, System.SR.Format(System.SR.Cryptography_UnknownHashAlgorithm, hashAlgorithm.Name));
49 }
50 oidValue = "1.2.840.113549.1.1.13";
51 }
52 AsnWriter asnWriter = new AsnWriter(AsnEncodingRules.DER);
53 asnWriter.PushSequence();
54 asnWriter.WriteObjectIdentifier(oidValue);
55 asnWriter.WriteNull();
56 asnWriter.PopSequence();
57 return asnWriter.Encode();
58 }
59}
void WriteObjectIdentifier(string oidValue, Asn1Tag? tag=null)
Definition AsnWriter.cs:954
Scope PushSequence(Asn1Tag? tag=null)
int Encode(Span< byte > destination)
Definition AsnWriter.cs:195
void WriteNull(Asn1Tag? tag=null)
Definition AsnWriter.cs:880
void PopSequence(Asn1Tag? tag=null)
static string Cryptography_UnknownHashAlgorithm
Definition SR.cs:152
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
Definition SR.cs:7
virtual byte[] ExportRSAPublicKey()
Definition RSA.cs:347
byte[] SignData(byte[] data, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
Definition RSA.cs:173
override byte[] SignData(byte[] data, HashAlgorithmName hashAlgorithm)