Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Rsa.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Security.Cryptography;
5
7{
11 public abstract class Rsa : SignatureAlgorithm
12 {
13 private readonly RSA rsa;
14
19 public Rsa(RSA RSA)
20 {
21 this.rsa = RSA;
22 }
23
27 public override string PkiAlgorithmOID => "1.2.840.113549.1.1.1";
28
33 {
34 get;
35 }
36
41 public override void ExportPublicKey(DerEncoder Output)
42 {
43 RSAParameters Parameters = this.rsa.ExportParameters(false);
44
45 Output.StartSEQUENCE();
46 Output.INTEGER(Parameters.Modulus, false);
47 Output.INTEGER(Parameters.Exponent, false);
48 Output.EndSEQUENCE();
49 }
50
55 public override void ExportPrivateKey(DerEncoder Output)
56 {
57 RSAParameters Parameters = this.rsa.ExportParameters(true);
58
59 Output.StartSEQUENCE();
60 Output.INTEGER(0); // Version
61 Output.INTEGER(Parameters.Modulus, false);
62 Output.INTEGER(Parameters.Exponent, false);
63 Output.INTEGER(Parameters.D, false);
64 Output.INTEGER(Parameters.P, false);
65 Output.INTEGER(Parameters.Q, false);
66 Output.INTEGER(Parameters.DP, false);
67 Output.INTEGER(Parameters.DQ, false);
68 Output.INTEGER(Parameters.InverseQ, false);
69 Output.EndSEQUENCE();
70 }
71
77 public override byte[] Sign(byte[] Data)
78 {
79 return this.rsa.SignData(Data, this.HashAlgorithmName, RSASignaturePadding.Pkcs1);
80 }
81 }
82}
Encodes data using the Distinguished Encoding Rules (DER), as defined in X.690
Definition: DerEncoder.cs:40
void EndSEQUENCE()
Ends the current SEQUENCE.
Definition: DerEncoder.cs:483
void INTEGER(long Value)
Encodes an INTEGER value.
Definition: DerEncoder.cs:99
void StartSEQUENCE()
Starts a SEQUENCE.
Definition: DerEncoder.cs:465
Base class for RSA algorithms
Definition: Rsa.cs:12
override void ExportPrivateKey(DerEncoder Output)
Exports the private key using DER.
Definition: Rsa.cs:55
Rsa(RSA RSA)
Base class for RSA algorithms
Definition: Rsa.cs:19
abstract HashAlgorithmName HashAlgorithmName
Name of hash algorithm to use for signatues.
Definition: Rsa.cs:33
override void ExportPublicKey(DerEncoder Output)
Exports the public key using DER.
Definition: Rsa.cs:41
override byte[] Sign(byte[] Data)
Signs data.
Definition: Rsa.cs:77
override string PkiAlgorithmOID
Object Identity for the PKI algorithm.
Definition: Rsa.cs:27
Abstract base class for signature algorithms