2using System.Formats.Asn1;
3using System.Globalization;
31 Client?.
Error(
"No RSA public key provided or found.");
35 int Bits = (int)RsaParameters.Modulus.GetBitLength();
40 RsaParameters.Modulus, RsaParameters.Exponent, Client);
59 StringBuilder? Msg = HasSniffer ?
new StringBuilder() :
null;
63 Msg!.AppendLine(
"RSS-PKCS1 signature verification parameters:");
64 Msg.Append(
"n (Modulus, dec): ");
65 Msg.AppendLine(Modulus.ToString(CultureInfo.InvariantCulture));
66 Msg.Append(
"e (Exponent, dec): ");
67 Msg.AppendLine(Exponent.ToString(CultureInfo.InvariantCulture));
68 Msg.Append(
"S (Signature, dec): ");
69 Msg.AppendLine(S.ToString(CultureInfo.InvariantCulture));
70 Msg.Append(
"Message (hex): ");
74 while (!Exponent.IsZero)
83 int K = Modulus.GetByteCount(
true);
84 byte[] EncodedMessage = EM.ToByteArray(
true,
true);
86 if (EncodedMessage.Length > K)
91 Client.
Error(
"Encoded message too long. Invalid signature.");
97 int c = EncodedMessage.Length;
100 byte[] Padded =
new byte[K];
101 Buffer.BlockCopy(EncodedMessage, 0, Padded, K - c, c);
102 EncodedMessage = Padded;
107 Msg!.Append(
"EM = S^e (hex): ");
115 Msg!.Append(
"Hash Digest (hex): ");
119 AsnWriter w =
new(AsnEncodingRules.DER);
126 w.WriteOctetString(HashDigest);
129 byte[] DigestInfo = w.Encode();
133 Msg!.Append(
"DigestInfo (hex): ");
137 if (c < DigestInfo.Length + 11)
142 Client.
Error(
"Encoded message & DigestInfo length mismatch. Invalid signature.");
148 if (EncodedMessage[0] != 0x00 || EncodedMessage[1] != 0x01)
153 Client.
Error(
"Encoded message not prefixed correctly. Invalid signature.");
161 while (Index < c && EncodedMessage[Index] == 0xff)
164 if (Index < 10 || Index >= c || EncodedMessage[Index] != 0x00)
169 Client.
Error(
"Encoded message not padded correctly. Invalid signature.");
177 if (c - Index + 1 != DigestInfo.Length)
182 Client.
Error(
"Padding length not correct. Invalid signature.");
188 for (
int i = 0; i < DigestInfo.Length; i++)
190 if (EncodedMessage[Index + i] != DigestInfo[i])
195 Client.
Error(
"DigestInfo not encoded correctly into encoded message. Invalid signature.");
Static class for parsing and decoding security objects encoded using Abstract Syntax Notation 1 (ASN....
static int ReportAlgorithmUse(string Name)
Records an Elliptic Curve has been used.
Abstract base class for public keys.
The RSA Public Key object does not have an OID of its own. Instead, it uses the OID of rsaEncryption ...
override bool VerifySignature(byte[] Data, byte[] Signature, IPublicKey PublicKey, ICommunicationLayer? Client)
Verifies a digital signature.
bool VerifySignatureRsaPkcs1(byte[] Data, byte[] Signature, BigInteger Modulus, BigInteger Exponent, ICommunicationLayer? Client)
Verifies a digital signature, using RSA PKCS#1 v1.5.
abstract string HashAlgorithmOid
OID of Hash algorithm to use.
abstract HashFunctionArray HashAlgorithm
Hash algorithm to use.
Abstract base class for signature algorithms, as defined in RFC 5280.
override string ToString()
Abstract base class for elliptic curves.
static BigInteger ToInt(byte[] Binary, bool BigEndian)
Converts a little-endian binary representation of a big integer to a BigInteger.
Integer arithmetic, modulus a prime.
BigInteger Multiply(BigInteger a, BigInteger b)
Multiplies two numbers, modulus p
Contains methods for simple hash calculations.
static string BinaryToString(byte[] Data)
Converts an array of bytes to a string with their hexadecimal representations (in lower case).
Interface for public keys.
void Information(string Comment)
Called to inform the viewer of something.
void Error(string Error)
Called to inform the viewer of an error state.
Interface for observable classes implementing communication protocols.
bool HasSniffers
If there are sniffers registered on the object.
delegate byte[] HashFunctionArray(byte[] Data)
Delegate to hash function.